Compare commits

..
12 Commits
Author SHA1 Message Date
lun_admin 65450ad017 ... 2025-06-16 17:13:46 +09:00
KJG 68b3d26994 . 2025-06-16 10:27:23 +09:00
Kelp 5a70698f50 updated the submodule xctool and the test script. 2014-05-08 11:01:47 +08:00
Kelp 59983c708a support Xcode5.1 2014-04-28 12:12:17 +08:00
Kelp 67a8f65982 updated Installation at readme 2014-01-27 11:33:03 +08:00
Kelp f92efd7088 added the submodule xctool. 2014-01-27 11:12:56 +08:00
Kelp cf48a7eb1b removed the submodule xctool. 2014-01-27 11:05:25 +08:00
Kelp a7161a78d9 updated Base64 module. 2014-01-27 11:03:30 +08:00
Kelp d49fa1cd57 updated submodule xctool 2013-12-30 10:53:11 +08:00
Kelp 2ff50207a5 fixed test script 2013-11-21 17:09:22 +08:00
Kelp d847b22024 fixed .travis.yml. renamed CocoaSecurity Test as CocoaSecurityTest. 2013-11-21 16:41:04 +08:00
Kelp 2f3a29d6d0 added test scripts for TravisCI 2013-11-21 13:27:26 +08:00
20 changed files with 513 additions and 573 deletions
+6 -2
View File
@@ -1,4 +1,8 @@
[submodule "xctool"]
path = xctool
[submodule "submodules/Base64"]
path = submodules/Base64
url = https://github.com/nicklockwood/Base64.git
ignore = dirty
[submodule "submodules/xctool"]
path = submodules/xctool
url = https://github.com/facebook/xctool.git
ignore = dirty
+3 -3
View File
@@ -1,6 +1,6 @@
language: objective-c
script:
- xctool/xctool.sh -project CocoaSecurity.xcodeproj -scheme CocoaSecurity -sdk iphonesimulator build
# waiting for xcode 5
# - xctool/xctool.sh -project CocoaSecurity.xcodeproj -scheme CocoaSecurity test -test-sdk iphonesimulator6.1
- submodules/xctool/xctool.sh -project CocoaSecurity.xcodeproj -scheme CocoaSecurity -sdk iphonesimulator build
- submodules/xctool/xctool.sh -project CocoaSecurity.xcodeproj -scheme CocoaSecurity -sdk iphonesimulator test -test-sdk iphonesimulator7.0
- submodules/xctool/xctool.sh -project CocoaSecurity.xcodeproj -scheme CocoaSecurity -sdk iphonesimulator test -test-sdk iphonesimulator7.1
@@ -1,65 +0,0 @@
//
// CocoaSecurityDecoder_Tests.m
// CocoaSecurity
//
// Created by Kelp on 2013/10/04.
//
//
#import <XCTest/XCTest.h>
#import "CocoaSecurity.h"
@interface CocoaSecurityDecoder_Tests : XCTestCase {
CocoaSecurityDecoder *_decoder;
}
@end
@implementation CocoaSecurityDecoder_Tests
- (void)setUp
{
[super setUp];
_decoder = [CocoaSecurityDecoder new];
}
- (void)tearDown
{
// Put teardown code here; it will be run once, after the last test case.
[super tearDown];
}
- (void)testDecodeHex
{
NSData *expected = [@"AO" dataUsingEncoding:NSUTF8StringEncoding];
NSData *actual = [_decoder hex:@"414F"];
XCTAssertEqualObjects(expected, actual, @"");
actual = [_decoder hex:@"414f"];
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testDecodeHexNil
{
NSData *actual = [_decoder hex:@""];
XCTAssertNil(actual, @"");
}
- (void)testDecodeBase64
{
NSData *expected = [@"source" dataUsingEncoding:NSUTF8StringEncoding];
NSData *actual = [_decoder base64:@"c291cmNl"];
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testDecodeBase64Nil
{
NSData *actual = [_decoder base64:@""];
XCTAssertNil(actual, @"");
}
@end
@@ -1,69 +0,0 @@
//
// CocoaSecurity_Tests.m
// CocoaSecurity Tests
//
// Created by Kelp on 2013/10/04.
//
//
#import <XCTest/XCTest.h>
#import "CocoaSecurity.h"
@interface CocoaSecurityEncoder_Tests : XCTestCase {
CocoaSecurityEncoder *_encoder;
}
@end
@implementation CocoaSecurityEncoder_Tests
- (void)setUp
{
[super setUp];
_encoder = [CocoaSecurityEncoder new];
}
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testEncodeHex
{
NSString *expected = @"414F";
NSData *data = [@"AO" dataUsingEncoding:NSUTF8StringEncoding];
NSString *actual = [_encoder hex:data useLower:NO];
XCTAssertEqualObjects(expected, actual, @"");
expected = @"414f";
actual = [_encoder hex:data useLower:YES];
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testEncodeHexNil
{
NSString *actual = [_encoder hex:[NSData new] useLower:YES];
XCTAssertNil(actual, @"");
}
- (void)testEncodeBase64
{
NSString *expected = @"c291cmNl";
NSData *data = [@"source" dataUsingEncoding:NSUTF8StringEncoding];
NSString *actual = [_encoder base64:data];
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testEncodeBase64Nil
{
NSString *actual = [_encoder base64:[NSData new]];
XCTAssertNil(actual, @"");
}
@end
@@ -1,71 +0,0 @@
//
// CocoaSecurityResult_Test.m
// CocoaSecurity
//
// Created by Kelp on 2013/10/04.
//
//
#import <XCTest/XCTest.h>
# import "CocoaSecurity.h"
@interface CocoaSecurityResult_Test : XCTestCase {
unsigned char *_data;
CocoaSecurityResult *_result;
}
@end
@implementation CocoaSecurityResult_Test
- (void)setUp
{
[super setUp];
unsigned char data[] =
{
0xcd, 0x3d, 0x4f, 0x4b, 0xae, 0x0c, 0x9d, 0x72,
0x14, 0x0c, 0x25, 0x22, 0xcb, 0x5d, 0xd1, 0x46
};
_data = malloc(16);
memcpy(_data, data, 16);
_result = [[CocoaSecurityResult alloc] initWithBytes:_data length:16];
}
- (void)tearDown
{
// Put teardown code here; it will be run once, after the last test case.
[super tearDown];
}
- (void)testBase64
{
NSString *expected = @"zT1PS64MnXIUDCUiy13RRg==";
NSString *actual = _result.base64;
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testHex
{
NSString *expected = @"CD3D4F4BAE0C9D72140C2522CB5DD146";
NSString *actual = _result.hex;
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testHexLower
{
NSString *expected = @"cd3d4f4bae0c9d72140c2522cb5dd146";
NSString *actual = _result.hexLower;
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testData
{
NSData *expected = [NSData dataWithBytes:_data length:16];
NSData *actual = _result.data;
XCTAssertEqualObjects(expected, actual, @"");
}
@end
-198
View File
@@ -1,198 +0,0 @@
//
// CocoaSecurity_Tests.m
// CocoaSecurity Tests
//
// Created by Kelp on 2013/10/04.
//
//
#import <XCTest/XCTest.h>
#import "CocoaSecurity.h"
@interface CocoaSecurity_Tests : XCTestCase
@end
@implementation CocoaSecurity_Tests
- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testEncryptAES128
{
NSString *expected = @"zT1PS64MnXIUDCUiy13RRg==";
CocoaSecurityResult *actual = [CocoaSecurity aesEncrypt:@"kelp"
hexKey:@"C40C69779E15780ADAE46C45EB451E23"
hexIv:@"CC0A69779E15780ADAE46C45EB451A23"];
XCTAssertEqualObjects(expected, actual.base64, @"");
}
- (void)testEncryptAES192
{
NSString *expected = @"zSpp/l/B/Gp+j0vByqcTVg==";
CocoaSecurityResult *actual = [CocoaSecurity aesEncrypt:@"kelp"
hexKey:@"C40C69779E15780ADAE46C45EB451E230000000000000000"
hexIv:@"CC0A69779E15780ADAE46C45EB451A23"];
XCTAssertEqualObjects(expected, actual.base64, @"");
}
- (void)testEncryptAES256
{
NSString *expected = @"WQYg5qvcGyCBY3IF0hPsoQ==";
CocoaSecurityResult *actual = [CocoaSecurity aesEncrypt:@"kelp"
hexKey:@"280f8bb8c43d532f389ef0e2a5321220b0782b065205dcdfcb8d8f02ed5115b9"
hexIv:@"CC0A69779E15780ADAE46C45EB451A23"];
XCTAssertEqualObjects(expected, actual.base64, @"");
}
- (void)testEncryptAESDefault
{
NSString *expected = @"ez9uubPneV1d2+rpjnabJw==";
CocoaSecurityResult *actual = [CocoaSecurity aesEncrypt:@"kelp" key:@"key"];
XCTAssertEqualObjects(expected, actual.base64, @"");
}
- (void)testDecryptAES128
{
NSString *expected = @"kelp";
CocoaSecurityResult *actual = [CocoaSecurity aesDecryptWithBase64:@"zT1PS64MnXIUDCUiy13RRg=="
hexKey:@"C40C69779E15780ADAE46C45EB451E23"
hexIv:@"CC0A69779E15780ADAE46C45EB451A23"];
XCTAssertEqualObjects(expected, actual.utf8String, @"");
}
- (void)testDecryptAES192
{
NSString *expected = @"kelp";
CocoaSecurityResult *actual = [CocoaSecurity aesDecryptWithBase64:@"zSpp/l/B/Gp+j0vByqcTVg=="
hexKey:@"C40C69779E15780ADAE46C45EB451E230000000000000000"
hexIv:@"CC0A69779E15780ADAE46C45EB451A23"];
XCTAssertEqualObjects(expected, actual.utf8String, @"");
}
- (void)testDecryptAES256
{
NSString *expected = @"kelp";
CocoaSecurityResult *actual = [CocoaSecurity aesDecryptWithBase64:@"WQYg5qvcGyCBY3IF0hPsoQ=="
hexKey:@"280f8bb8c43d532f389ef0e2a5321220b0782b065205dcdfcb8d8f02ed5115b9"
hexIv:@"CC0A69779E15780ADAE46C45EB451A23"];
XCTAssertEqualObjects(expected, actual.utf8String, @"");
}
- (void)testDecryptAESDefault
{
NSString *expected = @"kelp";
CocoaSecurityResult *actual = [CocoaSecurity aesDecryptWithBase64:@"ez9uubPneV1d2+rpjnabJw==" key:@"key"];
XCTAssertEqualObjects(expected, actual.utf8String, @"");
}
- (void)testMD5
{
NSString *expected = @"C40C69779E15780ADAE46C45EB451E23";
CocoaSecurityResult *md5 = [CocoaSecurity md5:@"kelp"];
NSString *actual = md5.hex;
XCTAssertEqualObjects(expected, actual , @"");
}
- (void)testHmacMD5
{
NSString *expected = @"2DFF352719234D5D6A9839FD8F43C8D2";
CocoaSecurityResult *hmacMd5 = [CocoaSecurity hmacMd5:@"kelp" hmacKey:@"key"];
NSString *actual = hmacMd5.hex;
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testSHA1
{
NSString *expected = @"70b6a0495fb444a63297c83de187b1730a18e85a";
CocoaSecurityResult *sha1 = [CocoaSecurity sha1:@"kelp"];
NSString *actual = sha1.hexLower;
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testSHA224
{
NSString *expected = @"1e124576cebf14ecdac30b8ca05ff94deb343f54ebb0eab21559dcf1";
CocoaSecurityResult *sha224 = [CocoaSecurity sha224:@"kelp"];
NSString *actual = sha224.hexLower;
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testSHA256
{
NSString *expected = @"280f8bb8c43d532f389ef0e2a5321220b0782b065205dcdfcb8d8f02ed5115b9";
CocoaSecurityResult *sha256 = [CocoaSecurity sha256:@"kelp"];
NSString *actual = sha256.hexLower;
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testSHA384
{
NSString *expected = @"e0801e06e6eea6257018bc0f2aaf1f7ec23385ce2ac9865fe209322262f323e80c81f65e711e30d162af5638ef8b4334";
CocoaSecurityResult *sha384 = [CocoaSecurity sha384:@"kelp"];
NSString *actual = sha384.hexLower;
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testSHA512
{
NSString *expected = @"af8489a9fb6dcb8973515cdda3366c939ebcc8ac8fb0a7c322f1333babe03655222930ad48b4924f1a1f13c23856bc3c2e1b93cb10c74e72362e5457756517ff";
CocoaSecurityResult *sha512 = [CocoaSecurity sha512:@"kelp"];
NSString *actual = sha512.hexLower;
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testHmacSHA1
{
NSString *expected = @"fae888da051e44eb0c57f43935ad82cdbedf482f";
CocoaSecurityResult *sha1 = [CocoaSecurity hmacSha1:@"kelp" hmacKey:@"key"];
NSString *actual = sha1.hexLower;
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testHmacSHA224
{
NSString *expected = @"4777556ee573705fcf6194de22947e09562653a84684c4b015a91e0c";
CocoaSecurityResult *sha224 = [CocoaSecurity hmacSha224:@"kelp" hmacKey:@"key"];
NSString *actual = sha224.hexLower;
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testHmacSHA256
{
NSString *expected = @"09e6c01ee44e4fc87871d3d8eb5265b67a941e9bf68d1b33851aeeed0114cd33";
CocoaSecurityResult *sha256 = [CocoaSecurity hmacSha256:@"kelp" hmacKey:@"key"];
NSString *actual = sha256.hexLower;
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testHmacSHA384
{
NSString *expected = @"99f2a12918f5e0c7e21ef4759ecb8dd882c95af32a204ac83928aa413e1d8e9ed312c29c41e2f3c00a78d448df11d15e";
CocoaSecurityResult *sha384 = [CocoaSecurity hmacSha384:@"kelp" hmacKey:@"key"];
NSString *actual = sha384.hexLower;
XCTAssertEqualObjects(expected, actual, @"");
}
- (void)testHmacSHA512
{
NSString *expected = @"3807619fdaa2dd77e3dd554a627284406000a5c924db72202af0e6b1832789a94bacc710dc2b7da61fbfd6e1065dfe39085a872538f5b19fde112092c90d893a";
CocoaSecurityResult *sha512 = [CocoaSecurity hmacSha512:@"kelp" hmacKey:@"key"];
NSString *actual = sha512.hexLower;
XCTAssertEqualObjects(expected, actual, @"");
}
@end
+84 -65
View File
@@ -10,18 +10,20 @@
2113923B16EAD6AF00AFDF87 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2113923A16EAD6AF00AFDF87 /* Foundation.framework */; };
2113924016EAD6AF00AFDF87 /* CocoaSecurity.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 2113923F16EAD6AF00AFDF87 /* CocoaSecurity.h */; };
2113924216EAD6AF00AFDF87 /* CocoaSecurity.m in Sources */ = {isa = PBXBuildFile; fileRef = 2113924116EAD6AF00AFDF87 /* CocoaSecurity.m */; };
2164336617FEB509006C71F4 /* CocoaSecurityDecoder_Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2164336517FEB509006C71F4 /* CocoaSecurityDecoder_Tests.m */; };
2164336817FEB8B0006C71F4 /* CocoaSecurityResult_Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 2164336717FEB8B0006C71F4 /* CocoaSecurityResult_Test.m */; };
21BB8A2F17FEA0EC0032C38C /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21BB8A2E17FEA0EC0032C38C /* XCTest.framework */; };
21BB8A3017FEA0EC0032C38C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2113923A16EAD6AF00AFDF87 /* Foundation.framework */; };
21BB8A3717FEA0EC0032C38C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 21BB8A3517FEA0EC0032C38C /* InfoPlist.strings */; };
21BB8A3917FEA0EC0032C38C /* CocoaSecurity_Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 21BB8A3817FEA0EC0032C38C /* CocoaSecurity_Tests.m */; };
21BB8A4017FEA5190032C38C /* CocoaSecurity.m in Sources */ = {isa = PBXBuildFile; fileRef = 2113924116EAD6AF00AFDF87 /* CocoaSecurity.m */; };
21BB8A4317FEB3ED0032C38C /* CocoaSecurityEncoder_Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 21BB8A4217FEB3ED0032C38C /* CocoaSecurityEncoder_Tests.m */; };
215409ED183DD72F00E4C15B /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21BB8A2E17FEA0EC0032C38C /* XCTest.framework */; };
215409EE183DD72F00E4C15B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2113923A16EAD6AF00AFDF87 /* Foundation.framework */; };
215409F5183DD72F00E4C15B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 215409F3183DD72F00E4C15B /* InfoPlist.strings */; };
21540A02183DD7F000E4C15B /* CocoaSecurity_Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 215409FE183DD7F000E4C15B /* CocoaSecurity_Tests.m */; };
21540A03183DD7F000E4C15B /* CocoaSecurityDecoder_Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 215409FF183DD7F000E4C15B /* CocoaSecurityDecoder_Tests.m */; };
21540A04183DD7F000E4C15B /* CocoaSecurityEncoder_Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 21540A00183DD7F000E4C15B /* CocoaSecurityEncoder_Tests.m */; };
21540A05183DD7F000E4C15B /* CocoaSecurityResult_Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 21540A01183DD7F000E4C15B /* CocoaSecurityResult_Test.m */; };
21540A06183DD81A00E4C15B /* CocoaSecurity.m in Sources */ = {isa = PBXBuildFile; fileRef = 2113924116EAD6AF00AFDF87 /* CocoaSecurity.m */; };
21FB346C189601A6002F38DE /* Base64.m in Sources */ = {isa = PBXBuildFile; fileRef = 21FB346B189601A6002F38DE /* Base64.m */; };
21FB346D18960347002F38DE /* Base64.m in Sources */ = {isa = PBXBuildFile; fileRef = 21FB346B189601A6002F38DE /* Base64.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
21BB8A3B17FEA0EC0032C38C /* PBXContainerItemProxy */ = {
215409F9183DD72F00E4C15B /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 2113922F16EAD6AF00AFDF87 /* Project object */;
proxyType = 1;
@@ -50,15 +52,17 @@
2113924116EAD6AF00AFDF87 /* CocoaSecurity.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CocoaSecurity.m; sourceTree = "<group>"; };
2113924916EAD6AF00AFDF87 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
2113924B16EAD6AF00AFDF87 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
2164336517FEB509006C71F4 /* CocoaSecurityDecoder_Tests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CocoaSecurityDecoder_Tests.m; sourceTree = "<group>"; };
2164336717FEB8B0006C71F4 /* CocoaSecurityResult_Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CocoaSecurityResult_Test.m; sourceTree = "<group>"; };
21BB8A2D17FEA0EC0032C38C /* CocoaSecurity Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "CocoaSecurity Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
215409EC183DD72F00E4C15B /* CocoaSecurityTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CocoaSecurityTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
215409F2183DD72F00E4C15B /* CocoaSecurityTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "CocoaSecurityTests-Info.plist"; sourceTree = "<group>"; };
215409F4183DD72F00E4C15B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
215409F8183DD72F00E4C15B /* CocoaSecurityTests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CocoaSecurityTests-Prefix.pch"; sourceTree = "<group>"; };
215409FE183DD7F000E4C15B /* CocoaSecurity_Tests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CocoaSecurity_Tests.m; sourceTree = "<group>"; };
215409FF183DD7F000E4C15B /* CocoaSecurityDecoder_Tests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CocoaSecurityDecoder_Tests.m; sourceTree = "<group>"; };
21540A00183DD7F000E4C15B /* CocoaSecurityEncoder_Tests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CocoaSecurityEncoder_Tests.m; sourceTree = "<group>"; };
21540A01183DD7F000E4C15B /* CocoaSecurityResult_Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CocoaSecurityResult_Test.m; sourceTree = "<group>"; };
21BB8A2E17FEA0EC0032C38C /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
21BB8A3417FEA0EC0032C38C /* CocoaSecurity Tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "CocoaSecurity Tests-Info.plist"; sourceTree = "<group>"; };
21BB8A3617FEA0EC0032C38C /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
21BB8A3817FEA0EC0032C38C /* CocoaSecurity_Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CocoaSecurity_Tests.m; sourceTree = "<group>"; };
21BB8A3A17FEA0EC0032C38C /* CocoaSecurity Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CocoaSecurity Tests-Prefix.pch"; sourceTree = "<group>"; };
21BB8A4217FEB3ED0032C38C /* CocoaSecurityEncoder_Tests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CocoaSecurityEncoder_Tests.m; sourceTree = "<group>"; };
21FB346A189601A6002F38DE /* Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Base64.h; path = submodules/Base64/Base64/Base64.h; sourceTree = SOURCE_ROOT; };
21FB346B189601A6002F38DE /* Base64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Base64.m; path = submodules/Base64/Base64/Base64.m; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -70,12 +74,12 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
21BB8A2A17FEA0EC0032C38C /* Frameworks */ = {
215409E9183DD72F00E4C15B /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
21BB8A2F17FEA0EC0032C38C /* XCTest.framework in Frameworks */,
21BB8A3017FEA0EC0032C38C /* Foundation.framework in Frameworks */,
215409ED183DD72F00E4C15B /* XCTest.framework in Frameworks */,
215409EE183DD72F00E4C15B /* Foundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -86,7 +90,7 @@
isa = PBXGroup;
children = (
2113923C16EAD6AF00AFDF87 /* CocoaSecurity */,
21BB8A3217FEA0EC0032C38C /* CocoaSecurity Tests */,
215409F0183DD72F00E4C15B /* CocoaSecurityTests */,
2113923916EAD6AF00AFDF87 /* Frameworks */,
2113923816EAD6AF00AFDF87 /* Products */,
);
@@ -96,7 +100,7 @@
isa = PBXGroup;
children = (
2113923716EAD6AF00AFDF87 /* libCocoaSecurity.a */,
21BB8A2D17FEA0EC0032C38C /* CocoaSecurity Tests.xctest */,
215409EC183DD72F00E4C15B /* CocoaSecurityTests.xctest */,
);
name = Products;
sourceTree = "<group>";
@@ -115,34 +119,44 @@
2113923C16EAD6AF00AFDF87 /* CocoaSecurity */ = {
isa = PBXGroup;
children = (
21FB34691896019A002F38DE /* Submodules */,
2113923F16EAD6AF00AFDF87 /* CocoaSecurity.h */,
2113924116EAD6AF00AFDF87 /* CocoaSecurity.m */,
);
path = CocoaSecurity;
sourceTree = "<group>";
};
21BB8A3217FEA0EC0032C38C /* CocoaSecurity Tests */ = {
215409F0183DD72F00E4C15B /* CocoaSecurityTests */ = {
isa = PBXGroup;
children = (
21BB8A3817FEA0EC0032C38C /* CocoaSecurity_Tests.m */,
21BB8A4217FEB3ED0032C38C /* CocoaSecurityEncoder_Tests.m */,
2164336517FEB509006C71F4 /* CocoaSecurityDecoder_Tests.m */,
2164336717FEB8B0006C71F4 /* CocoaSecurityResult_Test.m */,
21BB8A3317FEA0EC0032C38C /* Supporting Files */,
215409FE183DD7F000E4C15B /* CocoaSecurity_Tests.m */,
215409FF183DD7F000E4C15B /* CocoaSecurityDecoder_Tests.m */,
21540A00183DD7F000E4C15B /* CocoaSecurityEncoder_Tests.m */,
21540A01183DD7F000E4C15B /* CocoaSecurityResult_Test.m */,
215409F1183DD72F00E4C15B /* Supporting Files */,
);
path = "CocoaSecurity Tests";
path = CocoaSecurityTests;
sourceTree = "<group>";
};
21BB8A3317FEA0EC0032C38C /* Supporting Files */ = {
215409F1183DD72F00E4C15B /* Supporting Files */ = {
isa = PBXGroup;
children = (
21BB8A3417FEA0EC0032C38C /* CocoaSecurity Tests-Info.plist */,
21BB8A3517FEA0EC0032C38C /* InfoPlist.strings */,
21BB8A3A17FEA0EC0032C38C /* CocoaSecurity Tests-Prefix.pch */,
215409F2183DD72F00E4C15B /* CocoaSecurityTests-Info.plist */,
215409F3183DD72F00E4C15B /* InfoPlist.strings */,
215409F8183DD72F00E4C15B /* CocoaSecurityTests-Prefix.pch */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
21FB34691896019A002F38DE /* Submodules */ = {
isa = PBXGroup;
children = (
21FB346A189601A6002F38DE /* Base64.h */,
21FB346B189601A6002F38DE /* Base64.m */,
);
name = Submodules;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -163,22 +177,22 @@
productReference = 2113923716EAD6AF00AFDF87 /* libCocoaSecurity.a */;
productType = "com.apple.product-type.library.static";
};
21BB8A2C17FEA0EC0032C38C /* CocoaSecurity Tests */ = {
215409EB183DD72F00E4C15B /* CocoaSecurityTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 21BB8A3D17FEA0EC0032C38C /* Build configuration list for PBXNativeTarget "CocoaSecurity Tests" */;
buildConfigurationList = 215409FD183DD72F00E4C15B /* Build configuration list for PBXNativeTarget "CocoaSecurityTests" */;
buildPhases = (
21BB8A2917FEA0EC0032C38C /* Sources */,
21BB8A2A17FEA0EC0032C38C /* Frameworks */,
21BB8A2B17FEA0EC0032C38C /* Resources */,
215409E8183DD72F00E4C15B /* Sources */,
215409E9183DD72F00E4C15B /* Frameworks */,
215409EA183DD72F00E4C15B /* Resources */,
);
buildRules = (
);
dependencies = (
21BB8A3C17FEA0EC0032C38C /* PBXTargetDependency */,
215409FA183DD72F00E4C15B /* PBXTargetDependency */,
);
name = "CocoaSecurity Tests";
productName = "CocoaSecurity Tests";
productReference = 21BB8A2D17FEA0EC0032C38C /* CocoaSecurity Tests.xctest */;
name = CocoaSecurityTests;
productName = CocoaSecurityTests;
productReference = 215409EC183DD72F00E4C15B /* CocoaSecurityTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */
@@ -187,9 +201,9 @@
2113922F16EAD6AF00AFDF87 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0500;
LastUpgradeCheck = 0510;
TargetAttributes = {
21BB8A2C17FEA0EC0032C38C = {
215409EB183DD72F00E4C15B = {
TestTargetID = 2113923616EAD6AF00AFDF87;
};
};
@@ -207,17 +221,17 @@
projectRoot = "";
targets = (
2113923616EAD6AF00AFDF87 /* CocoaSecurity */,
21BB8A2C17FEA0EC0032C38C /* CocoaSecurity Tests */,
215409EB183DD72F00E4C15B /* CocoaSecurityTests */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
21BB8A2B17FEA0EC0032C38C /* Resources */ = {
215409EA183DD72F00E4C15B /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
21BB8A3717FEA0EC0032C38C /* InfoPlist.strings in Resources */,
215409F5183DD72F00E4C15B /* InfoPlist.strings in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -228,37 +242,39 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
21FB346C189601A6002F38DE /* Base64.m in Sources */,
2113924216EAD6AF00AFDF87 /* CocoaSecurity.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
21BB8A2917FEA0EC0032C38C /* Sources */ = {
215409E8183DD72F00E4C15B /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2164336617FEB509006C71F4 /* CocoaSecurityDecoder_Tests.m in Sources */,
21BB8A4017FEA5190032C38C /* CocoaSecurity.m in Sources */,
21BB8A3917FEA0EC0032C38C /* CocoaSecurity_Tests.m in Sources */,
21BB8A4317FEB3ED0032C38C /* CocoaSecurityEncoder_Tests.m in Sources */,
2164336817FEB8B0006C71F4 /* CocoaSecurityResult_Test.m in Sources */,
21FB346D18960347002F38DE /* Base64.m in Sources */,
21540A06183DD81A00E4C15B /* CocoaSecurity.m in Sources */,
21540A05183DD7F000E4C15B /* CocoaSecurityResult_Test.m in Sources */,
21540A03183DD7F000E4C15B /* CocoaSecurityDecoder_Tests.m in Sources */,
21540A02183DD7F000E4C15B /* CocoaSecurity_Tests.m in Sources */,
21540A04183DD7F000E4C15B /* CocoaSecurityEncoder_Tests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
21BB8A3C17FEA0EC0032C38C /* PBXTargetDependency */ = {
215409FA183DD72F00E4C15B /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 2113923616EAD6AF00AFDF87 /* CocoaSecurity */;
targetProxy = 21BB8A3B17FEA0EC0032C38C /* PBXContainerItemProxy */;
targetProxy = 215409F9183DD72F00E4C15B /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */
21BB8A3517FEA0EC0032C38C /* InfoPlist.strings */ = {
215409F3183DD72F00E4C15B /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
21BB8A3617FEA0EC0032C38C /* en */,
215409F4183DD72F00E4C15B /* en */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
@@ -290,8 +306,8 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 6.1;
ONLY_ACTIVE_ARCH = NO;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
name = Debug;
@@ -313,7 +329,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 6.1;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
ONLY_ACTIVE_ARCH = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
@@ -326,6 +342,7 @@
DSTROOT = /tmp/CocoaSecurity.dst;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "";
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
ONLY_ACTIVE_ARCH = NO;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -339,6 +356,7 @@
DSTROOT = /tmp/CocoaSecurity.dst;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "";
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
ONLY_ACTIVE_ARCH = NO;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -346,7 +364,7 @@
};
name = Release;
};
21BB8A3E17FEA0EC0032C38C /* Debug */ = {
215409FB183DD72F00E4C15B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
@@ -370,12 +388,13 @@
GCC_WARN_UNUSED_FUNCTION = YES;
INFOPLIST_FILE = "CocoaSecurityTests/CocoaSecurityTests-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = xctest;
};
name = Debug;
};
21BB8A3F17FEA0EC0032C38C /* Release */ = {
215409FC183DD72F00E4C15B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
@@ -422,11 +441,11 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
21BB8A3D17FEA0EC0032C38C /* Build configuration list for PBXNativeTarget "CocoaSecurity Tests" */ = {
215409FD183DD72F00E4C15B /* Build configuration list for PBXNativeTarget "CocoaSecurityTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
21BB8A3E17FEA0EC0032C38C /* Debug */,
21BB8A3F17FEA0EC0032C38C /* Release */,
215409FB183DD72F00E4C15B /* Debug */,
215409FC183DD72F00E4C15B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0500"
LastUpgradeVersion = "0510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -32,7 +32,7 @@
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "21BB8A2C17FEA0EC0032C38C"
BlueprintIdentifier = "215409EB183DD72F00E4C15B"
BuildableName = "CocoaSecurityTests.xctest"
BlueprintName = "CocoaSecurityTests"
ReferencedContainer = "container:CocoaSecurity.xcodeproj">
+5 -91
View File
@@ -9,6 +9,7 @@
#import "CocoaSecurity.h"
#import <CommonCrypto/CommonHMAC.h>
#import <CommonCrypto/CommonCryptor.h>
//#import "Base64.h"
#pragma mark - CocoaSecurity
@implementation CocoaSecurity
@@ -419,51 +420,7 @@
// convert NSData to Base64
- (NSString *)base64:(NSData *)data
{
static const char lookup[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
long long inputLength = [data length];
const unsigned char *inputBytes = [data bytes];
long long maxOutputLength = (inputLength / 3 + 1) * 4;
unsigned char *outputBytes = (unsigned char *)malloc((unsigned long)maxOutputLength);
long long index;
long long outputLength = 0;
for (index = 0; index < inputLength - 2; index += 3)
{
outputBytes[outputLength++] = lookup[(inputBytes[index] & 0xFC) >> 2];
outputBytes[outputLength++] = lookup[((inputBytes[index] & 0x03) << 4) | ((inputBytes[index + 1] & 0xF0) >> 4)];
outputBytes[outputLength++] = lookup[((inputBytes[index + 1] & 0x0F) << 2) | ((inputBytes[index + 2] & 0xC0) >> 6)];
outputBytes[outputLength++] = lookup[inputBytes[index + 2] & 0x3F];
}
//handle left-over data
if (index == inputLength - 2)
{
// = terminator
outputBytes[outputLength++] = lookup[(inputBytes[index] & 0xFC) >> 2];
outputBytes[outputLength++] = lookup[((inputBytes[index] & 0x03) << 4) | ((inputBytes[index + 1] & 0xF0) >> 4)];
outputBytes[outputLength++] = lookup[(inputBytes[index + 1] & 0x0F) << 2];
outputBytes[outputLength++] = '=';
}
else if (index == inputLength - 1)
{
// == terminator
outputBytes[outputLength++] = lookup[(inputBytes[index] & 0xFC) >> 2];
outputBytes[outputLength++] = lookup[(inputBytes[index] & 0x03) << 4];
outputBytes[outputLength++] = '=';
outputBytes[outputLength++] = '=';
}
NSString *result;
if (outputLength >= 4)
{
//truncate data to match actual output length
outputBytes = realloc(outputBytes, (unsigned long)outputLength);
result = [[NSString alloc] initWithBytes:outputBytes length:(unsigned long)outputLength encoding:NSASCIIStringEncoding];
}
free(outputBytes);
return result;
return [data base64EncodedStringWithOptions:0];
}
// convert NSData to hex string
@@ -501,6 +458,8 @@
sourceData = nil;
free(resultData);
return result;
}
@@ -510,52 +469,7 @@
@implementation CocoaSecurityDecoder
- (NSData *)base64:(NSString *)string
{
static const char lookup[] =
{
99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 62, 99, 99, 99, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 99, 99, 99, 99, 99, 99,
99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 99, 99, 99, 99, 99,
99, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 99, 99, 99, 99, 99
};
NSData *inputData = [string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSUInteger inputLength = [inputData length];
const unsigned char *inputBytes = [inputData bytes];
NSMutableData *outputData = [NSMutableData dataWithLength:(inputLength / 4 + 1) * 3];
unsigned char *outputBytes = (unsigned char *)[outputData mutableBytes];
int accumulator = 0;
long long outputLength = 0;
unsigned char accumulated[] = {0, 0, 0, 0};
for (NSUInteger index = 0; index < inputLength; index++)
{
unsigned char decoded = lookup[inputBytes[index] & 0x7F];
if (decoded != 99)
{
accumulated[accumulator] = decoded;
if (accumulator == 3)
{
outputBytes[outputLength++] = (accumulated[0] << 2) | (accumulated[1] >> 4);
outputBytes[outputLength++] = (accumulated[1] << 4) | (accumulated[2] >> 2);
outputBytes[outputLength++] = (accumulated[2] << 6) | accumulated[3];
}
accumulator = (accumulator + 1) % 4;
}
}
//handle left-over data
if (accumulator > 0) outputBytes[outputLength] = (accumulated[0] << 2) | (accumulated[1] >> 4);
if (accumulator > 1) outputBytes[++outputLength] = (accumulated[1] << 4) | (accumulated[2] >> 2);
if (accumulator > 2) outputLength++;
//truncate data to match actual output length
outputData.length = outputLength;
return outputLength? outputData: nil;
return [[NSData alloc]initWithBase64EncodedString:string options:0];
}
- (NSData *)hex:(NSString *)data
{
@@ -0,0 +1,65 @@
////
//// CocoaSecurityDecoder_Tests.m
//// CocoaSecurity
////
//// Created by Kelp on 2013/10/04.
////
////
//
//#import <XCTest/XCTest.h>
//#import "CocoaSecurity.h"
//
//
//@interface CocoaSecurityDecoder_Tests : XCTestCase {
// CocoaSecurityDecoder *_decoder;
//}
//
//@end
//
//
//
//@implementation CocoaSecurityDecoder_Tests
//
//- (void)setUp
//{
// [super setUp];
//
// _decoder = [CocoaSecurityDecoder new];
//}
//
//- (void)tearDown
//{
// // Put teardown code here; it will be run once, after the last test case.
// [super tearDown];
//}
//
//- (void)testDecodeHex
//{
// NSData *expected = [@"AO" dataUsingEncoding:NSUTF8StringEncoding];
// NSData *actual = [_decoder hex:@"414F"];
// XCTAssertEqualObjects(expected, actual, @"");
//
// actual = [_decoder hex:@"414f"];
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//- (void)testDecodeHexNil
//{
// NSData *actual = [_decoder hex:@""];
// XCTAssertNil(actual, @"");
//}
//
//- (void)testDecodeBase64
//{
// NSData *expected = [@"source" dataUsingEncoding:NSUTF8StringEncoding];
// NSData *actual = [_decoder base64:@"c291cmNl"];
// XCTAssertEqualObjects(expected, actual, @"");
//}
//- (void)testDecodeBase64Nil
//{
// NSData *actual = [_decoder base64:@""];
// XCTAssertNil(actual, @"");
//}
//
//
//@end
@@ -0,0 +1,69 @@
////
//// CocoaSecurity_Tests.m
//// CocoaSecurity Tests
////
//// Created by Kelp on 2013/10/04.
////
////
//
//#import <XCTest/XCTest.h>
//#import "CocoaSecurity.h"
//
//
//@interface CocoaSecurityEncoder_Tests : XCTestCase {
// CocoaSecurityEncoder *_encoder;
//}
//@end
//
//
//
//@implementation CocoaSecurityEncoder_Tests
//
//- (void)setUp
//{
// [super setUp];
//
// _encoder = [CocoaSecurityEncoder new];
//}
//
//- (void)tearDown
//{
// // Put teardown code here. This method is called after the invocation of each test method in the class.
// [super tearDown];
//}
//
//
//- (void)testEncodeHex
//{
// NSString *expected = @"414F";
// NSData *data = [@"AO" dataUsingEncoding:NSUTF8StringEncoding];
// NSString *actual = [_encoder hex:data useLower:NO];
// XCTAssertEqualObjects(expected, actual, @"");
//
// expected = @"414f";
// actual = [_encoder hex:data useLower:YES];
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//- (void)testEncodeHexNil
//{
// NSString *actual = [_encoder hex:[NSData new] useLower:YES];
// XCTAssertNil(actual, @"");
//}
//
//- (void)testEncodeBase64
//{
// NSString *expected = @"c291cmNl";
// NSData *data = [@"source" dataUsingEncoding:NSUTF8StringEncoding];
// NSString *actual = [_encoder base64:data];
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//- (void)testEncodeBase64Nil
//{
// NSString *actual = [_encoder base64:[NSData new]];
// XCTAssertNil(actual, @"");
//}
//
//
//@end
@@ -0,0 +1,71 @@
////
//// CocoaSecurityResult_Test.m
//// CocoaSecurity
////
//// Created by Kelp on 2013/10/04.
////
////
//
//#import <XCTest/XCTest.h>
//# import "CocoaSecurity.h"
//
//
//@interface CocoaSecurityResult_Test : XCTestCase {
// unsigned char *_data;
// CocoaSecurityResult *_result;
//}
//
//@end
//
//@implementation CocoaSecurityResult_Test
//
//- (void)setUp
//{
// [super setUp];
//
// unsigned char data[] =
// {
// 0xcd, 0x3d, 0x4f, 0x4b, 0xae, 0x0c, 0x9d, 0x72,
// 0x14, 0x0c, 0x25, 0x22, 0xcb, 0x5d, 0xd1, 0x46
// };
// _data = malloc(16);
// memcpy(_data, data, 16);
// _result = [[CocoaSecurityResult alloc] initWithBytes:_data length:16];
//}
//
//- (void)tearDown
//{
// // Put teardown code here; it will be run once, after the last test case.
// [super tearDown];
//}
//
//- (void)testBase64
//{
// NSString *expected = @"zT1PS64MnXIUDCUiy13RRg==";
// NSString *actual = _result.base64;
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//- (void)testHex
//{
// NSString *expected = @"CD3D4F4BAE0C9D72140C2522CB5DD146";
// NSString *actual = _result.hex;
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//- (void)testHexLower
//{
// NSString *expected = @"cd3d4f4bae0c9d72140c2522cb5dd146";
// NSString *actual = _result.hexLower;
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//- (void)testData
//{
// NSData *expected = [NSData dataWithBytes:_data length:16];
// NSData *actual = _result.data;
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//
//@end
+198
View File
@@ -0,0 +1,198 @@
////
//// CocoaSecurity_Tests.m
//// CocoaSecurity Tests
////
//// Created by Kelp on 2013/10/04.
////
////
//
//#import <XCTest/XCTest.h>
//#import "CocoaSecurity.h"
//
//
//@interface CocoaSecurity_Tests : XCTestCase
//
//@end
//
//
//
//@implementation CocoaSecurity_Tests
//
//- (void)setUp
//{
// [super setUp];
// // Put setup code here. This method is called before the invocation of each test method in the class.
//}
//
//- (void)tearDown
//{
// // Put teardown code here. This method is called after the invocation of each test method in the class.
// [super tearDown];
//}
//
//- (void)testEncryptAES128
//{
// NSString *expected = @"zT1PS64MnXIUDCUiy13RRg==";
// CocoaSecurityResult *actual = [CocoaSecurity aesEncrypt:@"kelp"
// hexKey:@"C40C69779E15780ADAE46C45EB451E23"
// hexIv:@"CC0A69779E15780ADAE46C45EB451A23"];
// XCTAssertEqualObjects(expected, actual.base64, @"");
//}
//
//- (void)testEncryptAES192
//{
// NSString *expected = @"zSpp/l/B/Gp+j0vByqcTVg==";
// CocoaSecurityResult *actual = [CocoaSecurity aesEncrypt:@"kelp"
// hexKey:@"C40C69779E15780ADAE46C45EB451E230000000000000000"
// hexIv:@"CC0A69779E15780ADAE46C45EB451A23"];
// XCTAssertEqualObjects(expected, actual.base64, @"");
//}
//
//- (void)testEncryptAES256
//{
// NSString *expected = @"WQYg5qvcGyCBY3IF0hPsoQ==";
// CocoaSecurityResult *actual = [CocoaSecurity aesEncrypt:@"kelp"
// hexKey:@"280f8bb8c43d532f389ef0e2a5321220b0782b065205dcdfcb8d8f02ed5115b9"
// hexIv:@"CC0A69779E15780ADAE46C45EB451A23"];
// XCTAssertEqualObjects(expected, actual.base64, @"");
//}
//
//- (void)testEncryptAESDefault
//{
// NSString *expected = @"ez9uubPneV1d2+rpjnabJw==";
// CocoaSecurityResult *actual = [CocoaSecurity aesEncrypt:@"kelp" key:@"key"];
// XCTAssertEqualObjects(expected, actual.base64, @"");
//}
//
//- (void)testDecryptAES128
//{
// NSString *expected = @"kelp";
// CocoaSecurityResult *actual = [CocoaSecurity aesDecryptWithBase64:@"zT1PS64MnXIUDCUiy13RRg=="
// hexKey:@"C40C69779E15780ADAE46C45EB451E23"
// hexIv:@"CC0A69779E15780ADAE46C45EB451A23"];
// XCTAssertEqualObjects(expected, actual.utf8String, @"");
//}
//
//- (void)testDecryptAES192
//{
// NSString *expected = @"kelp";
// CocoaSecurityResult *actual = [CocoaSecurity aesDecryptWithBase64:@"zSpp/l/B/Gp+j0vByqcTVg=="
// hexKey:@"C40C69779E15780ADAE46C45EB451E230000000000000000"
// hexIv:@"CC0A69779E15780ADAE46C45EB451A23"];
// XCTAssertEqualObjects(expected, actual.utf8String, @"");
//}
//
//- (void)testDecryptAES256
//{
// NSString *expected = @"kelp";
// CocoaSecurityResult *actual = [CocoaSecurity aesDecryptWithBase64:@"WQYg5qvcGyCBY3IF0hPsoQ=="
// hexKey:@"280f8bb8c43d532f389ef0e2a5321220b0782b065205dcdfcb8d8f02ed5115b9"
// hexIv:@"CC0A69779E15780ADAE46C45EB451A23"];
// XCTAssertEqualObjects(expected, actual.utf8String, @"");
//}
//
//- (void)testDecryptAESDefault
//{
// NSString *expected = @"kelp";
// CocoaSecurityResult *actual = [CocoaSecurity aesDecryptWithBase64:@"ez9uubPneV1d2+rpjnabJw==" key:@"key"];
// XCTAssertEqualObjects(expected, actual.utf8String, @"");
//}
//
//- (void)testMD5
//{
// NSString *expected = @"C40C69779E15780ADAE46C45EB451E23";
// CocoaSecurityResult *md5 = [CocoaSecurity md5:@"kelp"];
// NSString *actual = md5.hex;
// XCTAssertEqualObjects(expected, actual , @"");
//}
//
//- (void)testHmacMD5
//{
// NSString *expected = @"2DFF352719234D5D6A9839FD8F43C8D2";
// CocoaSecurityResult *hmacMd5 = [CocoaSecurity hmacMd5:@"kelp" hmacKey:@"key"];
// NSString *actual = hmacMd5.hex;
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//- (void)testSHA1
//{
// NSString *expected = @"70b6a0495fb444a63297c83de187b1730a18e85a";
// CocoaSecurityResult *sha1 = [CocoaSecurity sha1:@"kelp"];
// NSString *actual = sha1.hexLower;
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//- (void)testSHA224
//{
// NSString *expected = @"1e124576cebf14ecdac30b8ca05ff94deb343f54ebb0eab21559dcf1";
// CocoaSecurityResult *sha224 = [CocoaSecurity sha224:@"kelp"];
// NSString *actual = sha224.hexLower;
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//- (void)testSHA256
//{
// NSString *expected = @"280f8bb8c43d532f389ef0e2a5321220b0782b065205dcdfcb8d8f02ed5115b9";
// CocoaSecurityResult *sha256 = [CocoaSecurity sha256:@"kelp"];
// NSString *actual = sha256.hexLower;
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//- (void)testSHA384
//{
// NSString *expected = @"e0801e06e6eea6257018bc0f2aaf1f7ec23385ce2ac9865fe209322262f323e80c81f65e711e30d162af5638ef8b4334";
// CocoaSecurityResult *sha384 = [CocoaSecurity sha384:@"kelp"];
// NSString *actual = sha384.hexLower;
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//- (void)testSHA512
//{
// NSString *expected = @"af8489a9fb6dcb8973515cdda3366c939ebcc8ac8fb0a7c322f1333babe03655222930ad48b4924f1a1f13c23856bc3c2e1b93cb10c74e72362e5457756517ff";
// CocoaSecurityResult *sha512 = [CocoaSecurity sha512:@"kelp"];
// NSString *actual = sha512.hexLower;
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//- (void)testHmacSHA1
//{
// NSString *expected = @"fae888da051e44eb0c57f43935ad82cdbedf482f";
// CocoaSecurityResult *sha1 = [CocoaSecurity hmacSha1:@"kelp" hmacKey:@"key"];
// NSString *actual = sha1.hexLower;
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//- (void)testHmacSHA224
//{
// NSString *expected = @"4777556ee573705fcf6194de22947e09562653a84684c4b015a91e0c";
// CocoaSecurityResult *sha224 = [CocoaSecurity hmacSha224:@"kelp" hmacKey:@"key"];
// NSString *actual = sha224.hexLower;
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//- (void)testHmacSHA256
//{
// NSString *expected = @"09e6c01ee44e4fc87871d3d8eb5265b67a941e9bf68d1b33851aeeed0114cd33";
// CocoaSecurityResult *sha256 = [CocoaSecurity hmacSha256:@"kelp" hmacKey:@"key"];
// NSString *actual = sha256.hexLower;
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//- (void)testHmacSHA384
//{
// NSString *expected = @"99f2a12918f5e0c7e21ef4759ecb8dd882c95af32a204ac83928aa413e1d8e9ed312c29c41e2f3c00a78d448df11d15e";
// CocoaSecurityResult *sha384 = [CocoaSecurity hmacSha384:@"kelp" hmacKey:@"key"];
// NSString *actual = sha384.hexLower;
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//- (void)testHmacSHA512
//{
// NSString *expected = @"3807619fdaa2dd77e3dd554a627284406000a5c924db72202af0e6b1832789a94bacc710dc2b7da61fbfd6e1065dfe39085a872538f5b19fde112092c90d893a";
// CocoaSecurityResult *sha512 = [CocoaSecurity hmacSha512:@"kelp" hmacKey:@"key"];
// NSString *actual = sha512.hexLower;
// XCTAssertEqualObjects(expected, actual, @"");
//}
//
//
//@endå
+2
View File
@@ -96,6 +96,8 @@ NSData *data2 = [decoder base64:@"zT1PS64MnXIUDCUiy13RRg=="];
1. **git:**
```
$ git clone git://github.com/kelp404/CocoaSecurity.git
$ cd CocoaSecurity
$ git submodule update --init
```
2. **<a href="http://cocoapods.org/?q=CocoaSecurity" target="_blank">CocoadPods</a>:**
+1
Submodule submodules/Base64 added at bff0cc9be8
+1
Submodule submodules/xctool added at abe45bd3e8
Submodule xctool deleted from 9680172729