This commit is contained in:
Norio Nomura 2015-02-07 15:29:29 +09:00
Родитель 97120af602
Коммит fe15081f44
4 изменённых файлов: 43 добавлений и 8 удалений

Просмотреть файл

@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */
6C10E90F1A753A6C006EED90 /* Base32.h in Headers */ = {isa = PBXBuildFile; fileRef = 6CA0A79D1A74E80600AC539F /* Base32.h */; settings = {ATTRIBUTES = (Public, ); }; };
6C10E91A1A754346006EED90 /* TTTDataTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C10E9141A7540B5006EED90 /* TTTDataTransformer.m */; };
6C122F7D1A85E52C004FD458 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C122F7C1A85E52C004FD458 /* StringExtension.swift */; };
6C122F7E1A85E52C004FD458 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C122F7C1A85E52C004FD458 /* StringExtension.swift */; };
6CA0A79E1A74E80600AC539F /* Base32.h in Headers */ = {isa = PBXBuildFile; fileRef = 6CA0A79D1A74E80600AC539F /* Base32.h */; settings = {ATTRIBUTES = (Public, ); }; };
6CA0A7A41A74E80600AC539F /* Base32.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6CA0A7981A74E80600AC539F /* Base32.framework */; };
6CA0A7AB1A74E80600AC539F /* Base32Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CA0A7AA1A74E80600AC539F /* Base32Tests.swift */; };
@ -42,6 +44,7 @@
6C10E9121A7540B4006EED90 /* SecEncodeTransformTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SecEncodeTransformTests-Bridging-Header.h"; sourceTree = "<group>"; };
6C10E9131A7540B5006EED90 /* TTTDataTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TTTDataTransformer.h; sourceTree = "<group>"; };
6C10E9141A7540B5006EED90 /* TTTDataTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TTTDataTransformer.m; sourceTree = "<group>"; };
6C122F7C1A85E52C004FD458 /* StringExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = "<group>"; };
6CA0A7981A74E80600AC539F /* Base32.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Base32.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6CA0A79C1A74E80600AC539F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6CA0A79D1A74E80600AC539F /* Base32.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Base32.h; sourceTree = "<group>"; };
@ -152,6 +155,7 @@
children = (
6CA0A79D1A74E80600AC539F /* Base32.h */,
6CA0A7EF1A74ECEE00AC539F /* Base32.swift */,
6C122F7C1A85E52C004FD458 /* StringExtension.swift */,
6CA0A79B1A74E80600AC539F /* Supporting Files */,
);
path = Base32;
@ -479,6 +483,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6C122F7D1A85E52C004FD458 /* StringExtension.swift in Sources */,
6CA0A7F01A74ECEE00AC539F /* Base32.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -495,6 +500,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6C122F7E1A85E52C004FD458 /* StringExtension.swift in Sources */,
6CA0A7F11A74ECEE00AC539F /* Base32.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

Просмотреть файл

@ -106,8 +106,8 @@ extension NSData {
return base32Encode(self)
}
public var base32EncodedData: NSData? {
return base32EncodedString.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
public var base32EncodedData: NSData {
return base32EncodedString.dataUsingUTF8StringEncoding
}
public var base32DecodedData: NSData? {
@ -123,8 +123,8 @@ extension NSData {
return base32HexEncode(self)
}
public var base32HexEncodedData: NSData? {
return base32HexEncodedString.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
public var base32HexEncodedData: NSData {
return base32HexEncodedString.dataUsingUTF8StringEncoding
}
public var base32HexDecodedData: NSData? {

Просмотреть файл

@ -0,0 +1,29 @@
//
// StringExtension.swift
// Base32
//
// Created by on 2/7/15.
// Copyright (c) 2015 Norio Nomura. All rights reserved.
//
import Foundation
// MARK: - private
extension String {
/// NSData never nil
internal var dataUsingUTF8StringEncoding: NSData {
let length = nulTerminatedUTF8.count - 1
return nulTerminatedUTF8.withUnsafeBufferPointer {
return NSData(bytes: $0.baseAddress, length: length)
}
}
/// Array<UInt8>
internal var arrayUsingUTF8StringEncoding: [UInt8] {
let length = nulTerminatedUTF8.count - 1
return nulTerminatedUTF8.withUnsafeBufferPointer {
return Array(UnsafeBufferPointer(start: $0.baseAddress, count: length))
}
}
}

Просмотреть файл

@ -114,10 +114,10 @@ class Base32Tests: XCTestCase {
for (test, expect, expectHex) in dataVectors {
let result = test.base32EncodedData
let resultHex = test.base32HexEncodedData
XCTAssertEqual(result!, expect, "\(test).base32EncodedData")
XCTAssertEqual(resultHex!, expectHex, "\(test).base32HexEncodedData")
let decoded = result!.base32DecodedData
let decodedHex = resultHex!.base32HexDecodedData
XCTAssertEqual(result, expect, "\(test).base32EncodedData")
XCTAssertEqual(resultHex, expectHex, "\(test).base32HexEncodedData")
let decoded = result.base32DecodedData
let decodedHex = resultHex.base32HexDecodedData
XCTAssertEqual(decoded!, test, "\(result).base32DecodedData")
XCTAssertEqual(decodedHex!, test, "\(resultHex).base32HexDecodedData")
}