/*
* Base64Transcoder.c
* Base64Test
*
* Created by Jonathan Wight on Tue Mar 18 2003.
* Copyright (c) 2003 Toxic Software. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#include "Base64Transcoder.h"
#include <math.h>
#include <string.h>
const u_int8_t kBase64EncodeTable[64] = {
/* 0 */ 'A', /* 1 */ 'B', /* 2 */ 'C', /* 3 */ 'D',
/* 4 */ 'E', /* 5 */ 'F', /* 6 */ 'G', /* 7 */ 'H',
/* 8 */ 'I', /* 9 */ 'J', /* 10 */ 'K', /* 11 */ 'L',
/* 12 */ 'M', /* 13 */ 'N', /* 14 */ 'O', /* 15 */ 'P',
/* 16 */ 'Q', /* 17 */ 'R', /* 18 */ 'S', /* 19 */ 'T',
/* 20 */ 'U', /* 21 */ 'V', /* 22 */ 'W', /* 23 */ 'X',
/* 24 */ 'Y', /* 25 */ 'Z', /* 26 */ 'a', /* 27 */ 'b',
/* 28 */ 'c', /* 29 */ 'd', /* 30 */ 'e', /* 31 */ 'f',
/* 32 */ 'g', /* 33 */ 'h', /* 34 */ 'i', /* 35 */ 'j',
/* 36 */ 'k', /* 37 */ 'l', /* 38 */ 'm', /* 39 */ 'n',
/* 40 */ 'o', /* 41 */ 'p', /* 42 */ 'q', /* 43 */ 'r',
/* 44 */ 's', /* 45 */ 't', /* 46 */ 'u', /* 47 */ 'v',
/* 48 */ 'w', /* 49 */ 'x', /* 50 */ 'y', /* 51 */ 'z',
/* 52 */ '0', /* 53 */ '1', /* 54 */ '2', /* 55 */ '3',
/* 56 */ '4', /* 57 */ '5', /* 58 */ '6', /* 59 */ '7',
/* 60 */ '8', /* 61 */ '9', /* 62 */ '+', /* 63 */ '/'
};
/*
-1 = Base64 end of data marker.
-2 = White space (tabs, cr, lf, space)
-3 = Noise (all non whitespace, non-base64 characters)
-4 = Dangerous noise
-5 = Illegal noise (null byte)
*/
const int8_t kBase64DecodeTable[128] = {
/* 0x00 */ -5, /* 0x01 */ -3, /* 0x02 */ -3, /* 0x03 */ -3,
/* 0x04 */ -3, /* 0x05 */ -3, /* 0x06 */ -3, /* 0x07 */ -3,
/* 0x08 */ -3, /* 0x09 */ -2, /* 0x0a */ -2, /* 0x0b */ -2,
/* 0x0c */ -2, /* 0x0d */ -2, /* 0x0e */ -3, /* 0x0f */ -3,
/* 0x10 */ -3, /* 0x11 */ -3, /* 0x12 */ -3, /* 0x13 */ -3,
/* 0x14 */ -3, /* 0x15 */ -3, /* 0x16 */ -3, /* 0x17 */ -3,
/* 0x18 */ -3, /* 0x19 */ -3, /* 0x1a */ -3, /* 0x1b */ -3,
/* 0x1c */ -3, /* 0x1d */ -3, /* 0x1e */ -3, /* 0x1f */ -3,
/* ' ' */ -2, /* '!' */ -3, /* '"' */ -3, /* '#' */ -3,
/* '$' */ -3, /* '%' */ -3, /* '&' */ -3, /* ''' */ -3,
/* '(' */ -3, /* ')' */ -3, /* '*' */ -3, /* '+' */ 62,
/* ',' */ -3, /* '-' */ -3, /* '.' */ -3, /* '/' */ 63,
/* '0' */ 52, /* '1' */ 53, /* '2' */ 54, /* '3' */ 55,
/* '4' */ 56, /* '5' */ 57, /* '6' */ 58, /* '7' */ 59,
/* '8' */ 60, /* '9' */ 61, /* ':' */ -3, /* ';' */ -3,
/* '<' */ -3, /* '=' */ -1, /* '>' */ -3, /* '?' */ -3,
/* '@' */ -3, /* 'A' */ 0, /* 'B' */ 1, /* 'C' */ 2,
/* 'D' */ 3, /* 'E' */ 4, /* 'F' */ 5, /* 'G' */ 6,
/* 'H' */ 7, /* 'I' */ 8, /* 'J' */ 9, /* 'K' */ 10,
/* 'L' */ 11, /* 'M' */ 12, /* 'N' */ 13, /* 'O' */ 14,
/* 'P' */ 15, /* 'Q' */ 16, /* 'R' */ 17, /* 'S' */ 18,
/* 'T' */ 19, /* 'U' */ 20, /* 'V' */ 21, /* 'W' */ 22,
/* 'X' */ 23, /* 'Y' */ 24, /* 'Z' */ 25, /* '[' */ -3,
/* '\' */ -3, /* ']' */ -3, /* '^' */ -3, /* '_' */ -3,
/* '`' */ -3, /* 'a' */ 26, /* 'b' */ 27, /* 'c' */ 28,
/* 'd' */ 29, /* 'e' */ 30, /* 'f' */ 31, /* 'g' */ 32,
/* 'h' */ 33, /* 'i' */ 34, /* 'j' */ 35, /* 'k' */ 36,
/* 'l' */ 37, /* 'm' */ 38, /* 'n' */ 39, /* 'o' */ 40,
/* 'p' */ 41, /* 'q' */ 42, /* 'r' */ 43, /* 's' */ 44,
/* 't' */ 45, /* 'u' */ 46, /* 'v' */ 47, /* 'w' */ 48,
/* 'x' */ 49, /* 'y' */ 50, /* 'z' */ 51, /* '{' */ -3,
/* '|' */ -3, /* '}' */ -3, /* '~' */ -3, /* 0x7f */ -3
};
const u_int8_t kBits_00000011 = 0x03;
const u_int8_t kBits_00001111 = 0x0F;
const u_int8_t kBits_00110000 = 0x30;
const u_int8_t kBits_00111100 = 0x3C;
const u_int8_t kBits_00111111 = 0x3F;
const u_int8_t kBits_11000000 = 0xC0;
const u_int8_t kBits_11110000 = 0xF0;
const u_int8_t kBits_11111100 = 0xFC;
size_t EstimateBas64EncodedDataSize(size_t inDataSize)
{
size_t theEncodedDataSize = (int)ceil(inDataSize / 3.0) * 4;
theEncodedDataSize = theEncodedDataSize / 72 * 74 + theEncodedDataSize % 72;
return(theEncodedDataSize);
}
size_t EstimateBas64DecodedDataSize(size_t inDataSize)
{
size_t theDecodedDataSize = (int)ceil(inDataSize / 4.0) * 3;
//theDecodedDataSize = theDecodedDataSize / 72 * 74 + theDecodedDataSize % 72;
return(theDecodedDataSize);
}
bool Base64EncodeData(const void *inInputData, size_t inInputDataSize, char *outOutputData, size_t *ioOutputDataSize)
{
size_t theEncodedDataSize = EstimateBas64EncodedDataSize(inInputDataSize);
if (*ioOutputDataSize < theEncodedDataSize)
return(false);
*ioOutputDataSize = theEncodedDataSize;
const u_int8_t *theInPtr = (const u_int8_t *)inInputData;
u_int32_t theInIndex = 0, theOutIndex = 0;
for (; theInIndex < (inInputDataSize / 3) * 3; theInIndex += 3)
{
outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2];
outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (theInPtr[theInIndex + 1] & kBits_11110000) >> 4];
outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 1] & kBits_00001111) << 2 | (theInPtr[theInIndex + 2] & kBits_11000000) >> 6];
outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 2] & kBits_00111111) >> 0];
if (theOutIndex % 74 == 72)
{
outOutputData[theOutIndex++] = '\r';
outOutputData[theOutIndex++] = '\n';
}
}
const size_t theRemainingBytes = inInputDataSize - theInIndex;
if (theRemainingBytes == 1)
{
outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2];
outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (0 & kBits_11110000) >> 4];
outOutputData[theOutIndex++] = '=';
outOutputData[theOutIndex++] = '=';
if (theOutIndex % 74 == 72)
{
outOutputData[theOutIndex++] = '\r';
outOutputData[theOutIndex++] = '\n';
}
}
else if (theRemainingBytes == 2)
{
outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2];
outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (theInPtr[theInIndex + 1] & kBits_11110000) >> 4];
outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 1] & kBits_00001111) << 2 | (0 & kBits_11000000) >> 6];
outOutputData[theOutIndex++] = '=';
if (theOutIndex % 74 == 72)
{
outOutputData[theOutIndex++] = '\r';
outOutputData[theOutIndex++] = '\n';
}
}
return(true);
}
bool Base64DecodeData(const void *inInputData, size_t inInputDataSize, void *ioOutputData, size_t *ioOutputDataSize)
{
memset(ioOutputData, '.', *ioOutputDataSize);
size_t theDecodedDataSize = EstimateBas64DecodedDataSize(inInputDataSize);
if (*ioOutputDataSize < theDecodedDataSize)
return(false);
*ioOutputDataSize = 0;
const u_int8_t *theInPtr = (const u_int8_t *)inInputData;
u_int8_t *theOutPtr = (u_int8_t *)ioOutputData;
size_t theInIndex = 0, theOutIndex = 0;
u_int8_t theOutputOctet;
size_t theSequence = 0;
for (; theInIndex < inInputDataSize; )
{
int8_t theSextet = 0;
int8_t theCurrentInputOctet = theInPtr[theInIndex];
theSextet = kBase64D
没有合适的资源?快使用搜索试试~ 我知道了~
OAuthConsumer源码(iOS版)
共126个文件
svn-base:59个
h:26个
m:23个
5星 · 超过95%的资源 需积分: 3 16 下载量 14 浏览量
2012-03-20
09:05:15
上传
评论
收藏 156KB RAR 举报
温馨提示
完整的OAuthConsumer源码,官方下载地址http://code.google.com/p/oauthconsumer/
资源推荐
资源详情
资源评论
收起资源包目录
OAuthConsumer源码(iOS版) (126个子文件)
all-wcprops 7KB
all-wcprops 510B
all-wcprops 347B
all-wcprops 230B
Base64Transcoder.c 9KB
dir-prop-base 31B
entries 9KB
entries 711B
entries 528B
entries 386B
OAMutableURLRequest.h 2KB
NSMutableURLRequest+ParametersTest.h 2KB
OAAsynchronousDataFetcher.h 2KB
OAuthConsumer.h 2KB
OAMutableURLRequestTest.h 2KB
OADataFetcher.h 2KB
OAToken.h 2KB
OARequestParameter.h 2KB
OAServiceTicket.h 2KB
OATokenTest.h 2KB
Base64Transcoder.h 2KB
OARequestParameterTest.h 1KB
OAConsumer.h 1KB
OADataFetcherTest.h 1KB
NSMutableURLRequest+Parameters.h 1KB
OAHMAC_SHA1SignatureProviderTest.h 1KB
OAPlaintextSignatureProviderTest.h 1KB
NSString+URLEncodingTest.h 1KB
OASignatureProviding.h 1KB
OAHMAC_SHA1SignatureProvider.h 1KB
OAPlaintextSignatureProvider.h 1KB
NSURL+BaseTest.h 1KB
NSString+URLEncoding.h 1KB
OAConsumerTest.h 1KB
NSURL+Base.h 1KB
OAToken_KeychainExtensions.h 583B
NSMutableURLRequest+ParametersTest.m 8KB
OAMutableURLRequest.m 8KB
OAMutableURLRequestTest.m 6KB
OATokenTest.m 4KB
OAAsynchronousDataFetcher.m 4KB
NSMutableURLRequest+Parameters.m 4KB
OADataFetcherTest.m 3KB
OAToken.m 3KB
OAToken_KeychainExtensions.m 3KB
OADataFetcher.m 3KB
OAHMAC_SHA1SignatureProvider.m 2KB
OARequestParameterTest.m 2KB
OAHMAC_SHA1SignatureProviderTest.m 2KB
NSString+URLEncoding.m 2KB
OARequestParameter.m 2KB
NSURL+BaseTest.m 2KB
OAServiceTicket.m 2KB
NSString+URLEncodingTest.m 2KB
OAConsumerTest.m 2KB
OAPlaintextSignatureProviderTest.m 2KB
OAConsumer.m 2KB
OAPlaintextSignatureProvider.m 1KB
NSURL+Base.m 1KB
jon.mode1v3 45KB
project.pbxproj 44KB
jon.pbxuser 49KB
OAuthConsumer_Prefix.pch 158B
Info.plist 772B
OAuthConsumerTestSuite-Info.plist 624B
OATestServer.rb 1KB
InfoPlist.strings 200B
jon.pbxuser.svn-base 49KB
jon.mode1v3.svn-base 45KB
project.pbxproj.svn-base 44KB
Base64Transcoder.c.svn-base 9KB
NSMutableURLRequest+ParametersTest.m.svn-base 8KB
OAMutableURLRequest.m.svn-base 8KB
OAMutableURLRequestTest.m.svn-base 6KB
OATokenTest.m.svn-base 4KB
OAAsynchronousDataFetcher.m.svn-base 4KB
NSMutableURLRequest+Parameters.m.svn-base 4KB
OADataFetcherTest.m.svn-base 3KB
OAToken.m.svn-base 3KB
OAToken_KeychainExtensions.m.svn-base 3KB
OADataFetcher.m.svn-base 3KB
OAMutableURLRequest.h.svn-base 2KB
NSMutableURLRequest+ParametersTest.h.svn-base 2KB
OAHMAC_SHA1SignatureProvider.m.svn-base 2KB
OARequestParameterTest.m.svn-base 2KB
OAHMAC_SHA1SignatureProviderTest.m.svn-base 2KB
NSString+URLEncoding.m.svn-base 2KB
OARequestParameter.m.svn-base 2KB
NSURL+BaseTest.m.svn-base 2KB
OAAsynchronousDataFetcher.h.svn-base 2KB
OAuthConsumer.h.svn-base 2KB
OAMutableURLRequestTest.h.svn-base 2KB
OADataFetcher.h.svn-base 2KB
OAToken.h.svn-base 2KB
OARequestParameter.h.svn-base 2KB
OAServiceTicket.h.svn-base 2KB
OAServiceTicket.m.svn-base 2KB
OATokenTest.h.svn-base 2KB
Base64Transcoder.h.svn-base 2KB
NSString+URLEncodingTest.m.svn-base 2KB
共 126 条
- 1
- 2
资源评论
- 周敏2012-09-18东西是好,就是不能编译。
- Tom_Xizi2013-07-16代码是挺全的,就是不是很好理解
- gfyxyz20082012-07-21代码很不错,但无法编译
- cuijay2012-09-11楼上说得对 代码很不错 但是无法编译
- 「已注销」2012-11-06开源类库 很好很强大
lovenjoe
- 粉丝: 51
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功