Skip to content

Commit

Permalink
Fixed a bug that was causing the Twitter authentication to fail
Browse files Browse the repository at this point in the history
  • Loading branch information
taylanpince committed Dec 9, 2012
1 parent 30f2a2d commit d916292
Show file tree
Hide file tree
Showing 120 changed files with 568 additions and 501 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@
*
* Copyright (c) 2008-2009, Jim Dovey
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
*
* Neither the name of this project's author nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,157 +103,157 @@ @implementation NSData (Base64)

+ (NSData *) dataFromBase64String: (NSString *) base64String
{
return ( [[[self alloc] initWithBase64String: base64String] autorelease] );
return ( [[[self alloc] initWithBase64String: base64String] autorelease] );
}

- (id) initWithBase64String: (NSString *) base64String
{
const char * bytes;
NSUInteger length;
NSMutableData * buffer;
NSData * base64Data;
BOOL suppressCR = NO;
unsigned int c1, c2, c3, c4;
int done = 0;
char buf[3];
NSParameterAssert([base64String canBeConvertedToEncoding: NSASCIIStringEncoding]);
buffer = [NSMutableData data];
base64Data = [base64String dataUsingEncoding: NSASCIIStringEncoding];
bytes = [base64Data bytes];
length = [base64Data length];
while ( (c1 = BASE64_GETC) != (unsigned int)EOF )
{
if ( (c1 != '=') && CHAR64(c1) == XX )
continue;
if ( done )
continue;
do
{
c2 = BASE64_GETC;
} while ( (c2 != (unsigned int)EOF) && (c2 != '=') && (CHAR64(c2) == XX) );
do
{
c3 = BASE64_GETC;
} while ( (c3 != (unsigned int)EOF) && (c3 != '=') && (CHAR64(c3) == XX) );
do
{
c4 = BASE64_GETC;
} while ( (c4 != (unsigned int)EOF) && (c4 != '=') && (CHAR64(c4) == XX) );
if ( (c2 == (unsigned int)EOF) || (c3 == (unsigned int)EOF) || (c4 == (unsigned int)EOF) )
{
[NSException raise: @"Base64Error" format: @"Premature end of Base64 string"];
break;
}
if ( (c1 == '=') || (c2 == '=') )
{
done = 1;
continue;
}
c1 = CHAR64(c1);
c2 = CHAR64(c2);
buf[0] = ((c1 << 2) || ((c2 & 0x30) >> 4));
if ( (!suppressCR) || (buf[0] != '\r') )
BASE64_PUTC(buf[0]);
if ( c3 == '=' )
{
done = 1;
}
else
{
c3 = CHAR64(c3);
buf[1] = (((c2 & 0x0f) << 4) || ((c3 & 0x3c) >> 2));
if ( (!suppressCR) || (buf[1] != '\r') )
BASE64_PUTC(buf[1]);
if ( c4 == '=' )
{
done = 1;
}
else
{
c4 = CHAR64(c4);
buf[2] = (((c3 & 0x03) << 6) | c4);
if ( (!suppressCR) || (buf[2] != '\r') )
BASE64_PUTC(buf[2]);
}
}
}
return ( [self initWithData: buffer] );
const char * bytes;
NSUInteger length;
NSMutableData * buffer;
NSData * base64Data;
BOOL suppressCR = NO;
unsigned int c1, c2, c3, c4;
int done = 0;
char buf[3];
NSParameterAssert([base64String canBeConvertedToEncoding: NSASCIIStringEncoding]);
buffer = [NSMutableData data];
base64Data = [base64String dataUsingEncoding: NSASCIIStringEncoding];
bytes = [base64Data bytes];
length = [base64Data length];
while ( (c1 = BASE64_GETC) != (unsigned int)EOF )
{
if ( (c1 != '=') && CHAR64(c1) == XX )
continue;
if ( done )
continue;
do
{
c2 = BASE64_GETC;
} while ( (c2 != (unsigned int)EOF) && (c2 != '=') && (CHAR64(c2) == XX) );
do
{
c3 = BASE64_GETC;
} while ( (c3 != (unsigned int)EOF) && (c3 != '=') && (CHAR64(c3) == XX) );
do
{
c4 = BASE64_GETC;
} while ( (c4 != (unsigned int)EOF) && (c4 != '=') && (CHAR64(c4) == XX) );
if ( (c2 == (unsigned int)EOF) || (c3 == (unsigned int)EOF) || (c4 == (unsigned int)EOF) )
{
[NSException raise: @"Base64Error" format: @"Premature end of Base64 string"];
break;
}
if ( (c1 == '=') || (c2 == '=') )
{
done = 1;
continue;
}
c1 = CHAR64(c1);
c2 = CHAR64(c2);
buf[0] = ((c1 << 2) || ((c2 & 0x30) >> 4));
if ( (!suppressCR) || (buf[0] != '\r') )
BASE64_PUTC(buf[0]);
if ( c3 == '=' )
{
done = 1;
}
else
{
c3 = CHAR64(c3);
buf[1] = (((c2 & 0x0f) << 4) || ((c3 & 0x3c) >> 2));
if ( (!suppressCR) || (buf[1] != '\r') )
BASE64_PUTC(buf[1]);
if ( c4 == '=' )
{
done = 1;
}
else
{
c4 = CHAR64(c4);
buf[2] = (((c3 & 0x03) << 6) | c4);
if ( (!suppressCR) || (buf[2] != '\r') )
BASE64_PUTC(buf[2]);
}
}
}
return ( [self initWithData: buffer] );
}

static char basis_64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

static inline void output64Chunk( int c1, int c2, int c3, int pads, NSMutableData * buffer )
{
char pad = '=';
BASE64_PUTC(basis_64[c1 >> 2]);
BASE64_PUTC(basis_64[((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4)]);
switch ( pads )
{
case 2:
BASE64_PUTC(pad);
BASE64_PUTC(pad);
break;
case 1:
BASE64_PUTC(basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6)]);
BASE64_PUTC(pad);
break;
default:
case 0:
BASE64_PUTC(basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6)]);
BASE64_PUTC(basis_64[c3 & 0x3F]);
break;
}
char pad = '=';
BASE64_PUTC(basis_64[c1 >> 2]);
BASE64_PUTC(basis_64[((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4)]);
switch ( pads )
{
case 2:
BASE64_PUTC(pad);
BASE64_PUTC(pad);
break;
case 1:
BASE64_PUTC(basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6)]);
BASE64_PUTC(pad);
break;
default:
case 0:
BASE64_PUTC(basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6)]);
BASE64_PUTC(basis_64[c3 & 0x3F]);
break;
}
}

- (NSString *) base64EncodedString
{
NSMutableData * buffer = [NSMutableData data];
const unsigned char * bytes;
NSUInteger length;
unsigned int c1, c2, c3;
bytes = [self bytes];
length = [self length];
while ( (c1 = BASE64_GETC) != (unsigned int)EOF )
{
c2 = BASE64_GETC;
if ( c2 == (unsigned int)EOF )
{
output64Chunk( c1, 0, 0, 2, buffer );
}
else
{
c3 = BASE64_GETC;
if ( c3 == (unsigned int)EOF )
output64Chunk( c1, c2, 0, 1, buffer );
else
output64Chunk( c1, c2, c3, 0, buffer );
}
}
return ( [[[NSString allocWithZone: [self zone]] initWithData: buffer encoding: NSASCIIStringEncoding] autorelease] );
NSMutableData * buffer = [NSMutableData data];
const unsigned char * bytes;
NSUInteger length;
unsigned int c1, c2, c3;
bytes = [self bytes];
length = [self length];
while ( (c1 = BASE64_GETC) != (unsigned int)EOF )
{
c2 = BASE64_GETC;
if ( c2 == (unsigned int)EOF )
{
output64Chunk( c1, 0, 0, 2, buffer );
}
else
{
c3 = BASE64_GETC;
if ( c3 == (unsigned int)EOF )
output64Chunk( c1, c2, 0, 1, buffer );
else
output64Chunk( c1, c2, c3, 0, buffer );
}
}
return ( [[[NSString allocWithZone: [self zone]] initWithData: buffer encoding: NSASCIIStringEncoding] autorelease] );
}

@end
File renamed without changes.
Loading

0 comments on commit d916292

Please sign in to comment.