Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c-style functions #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions TMTumblrSDK/Authentication/TMOAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ - (NSString *)base64Encoding;

@interface TMOAuth()

NSString *generateBaseString(NSString *baseURL, NSString *method, NSDictionary *headers, NSDictionary *queryParameters,
NSString *TMOAuth_generateBaseString(NSString *baseURL, NSString *method, NSDictionary *headers, NSDictionary *queryParameters,
NSDictionary *postParameters);

NSString *sign(NSString *baseString, NSString *consumerSecret, NSString *tokenSecret);
NSString *TMOAuth_sign(NSString *baseString, NSString *consumerSecret, NSString *tokenSecret);

NSString *UNIXTimestamp(NSDate *date);
NSString *TMOAuth_UNIXTimestamp(NSDate *date);

NSData *HMACSHA1(NSString *dataString, NSString *keyString);
NSData *TMOAuth_HMACSHA1(NSString *dataString, NSString *keyString);

@end

Expand All @@ -50,7 +50,7 @@ - (id)initWithURL:(NSURL *)URL method:(NSString *)method postParameters:(NSDicti
token:(NSString *)token tokenSecret:(NSString *)tokenSecret {
if (self = [super init]) {
NSMutableDictionary *headerParameters = [[NSMutableDictionary alloc] initWithDictionary:@{
@"oauth_timestamp" : UNIXTimestamp([NSDate date]),
@"oauth_timestamp" : TMOAuth_UNIXTimestamp([NSDate date]),
@"oauth_nonce" : nonce,
@"oauth_version" : @"1.0",
@"oauth_signature_method" : @"HMAC-SHA1",
Expand All @@ -64,11 +64,11 @@ - (id)initWithURL:(NSURL *)URL method:(NSString *)method postParameters:(NSDicti

NSString *baseURLString = [[URL absoluteString] componentsSeparatedByString:@"?"][0];

NSString *baseString = generateBaseString(baseURLString, method, headerParameters, queryParameters, postParameters);
NSString *baseString = TMOAuth_generateBaseString(baseURLString, method, headerParameters, queryParameters, postParameters);

_baseString = baseString;

headerParameters[@"oauth_signature"] = sign(baseString, consumerSecret, tokenSecret);
headerParameters[@"oauth_signature"] = TMOAuth_sign(baseString, consumerSecret, tokenSecret);

NSMutableArray *components = [NSMutableArray array];

Expand All @@ -83,7 +83,7 @@ - (id)initWithURL:(NSURL *)URL method:(NSString *)method postParameters:(NSDicti

#pragma mark - Private

NSString *generateBaseString(NSString *baseURL, NSString *method, NSDictionary *headers, NSDictionary *queryParameters,
NSString *TMOAuth_generateBaseString(NSString *baseURL, NSString *method, NSDictionary *headers, NSDictionary *queryParameters,
NSDictionary *postParameters) {
NSMutableDictionary *signatureParameters = [NSMutableDictionary dictionaryWithDictionary:headers];
[signatureParameters addEntriesFromDictionary:queryParameters];
Expand All @@ -94,10 +94,10 @@ - (id)initWithURL:(NSURL *)URL method:(NSString *)method postParameters:(NSDicti
return [NSString stringWithFormat:@"%@&%@&%@", method, TMURLEncode(baseURL), TMURLEncode(parameterString)];
}

NSString *sign(NSString *baseString, NSString *consumerSecret, NSString *tokenSecret) {
NSString *TMOAuth_sign(NSString *baseString, NSString *consumerSecret, NSString *tokenSecret) {
NSString *keyString = [NSString stringWithFormat:@"%@&%@", consumerSecret, tokenSecret ? tokenSecret : @""];

NSData *hashedData = HMACSHA1(baseString, keyString);
NSData *hashedData = TMOAuth_HMACSHA1(baseString, keyString);
NSString *base64EncodedString = nil;

if ([hashedData respondsToSelector:@selector(base64EncodedStringWithOptions:)]) {
Expand All @@ -109,11 +109,11 @@ - (id)initWithURL:(NSURL *)URL method:(NSString *)method postParameters:(NSDicti
return base64EncodedString;
}

NSString *UNIXTimestamp(NSDate *date) {
NSString *TMOAuth_UNIXTimestamp(NSDate *date) {
return [NSString stringWithFormat:@"%f", round([date timeIntervalSince1970])];
}

NSData *HMACSHA1(NSString *dataString, NSString *keyString) {
NSData *TMOAuth_HMACSHA1(NSString *dataString, NSString *keyString) {
NSData *data = [dataString dataUsingEncoding:NSUTF8StringEncoding];
NSData *key = [keyString dataUsingEncoding:NSUTF8StringEncoding];

Expand Down