فهرست منبع

Refactor CRC -> Checksum

Marcin Krzyżanowski 9 سال پیش
والد
کامیت
38155dc72a

+ 11 - 11
CryptoSwift.xcodeproj/project.pbxproj

@@ -96,10 +96,10 @@
 		757BC9551C1CA5790093AAA9 /* ChaCha20.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757BC9201C1CA5790093AAA9 /* ChaCha20.swift */; };
 		757BC9561C1CA5790093AAA9 /* ChaCha20.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757BC9201C1CA5790093AAA9 /* ChaCha20.swift */; };
 		757BC9571C1CA5790093AAA9 /* ChaCha20.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757BC9201C1CA5790093AAA9 /* ChaCha20.swift */; };
-		757BC9601C1CA5790093AAA9 /* CRC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757BC9231C1CA5790093AAA9 /* CRC.swift */; };
-		757BC9611C1CA5790093AAA9 /* CRC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757BC9231C1CA5790093AAA9 /* CRC.swift */; };
-		757BC9621C1CA5790093AAA9 /* CRC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757BC9231C1CA5790093AAA9 /* CRC.swift */; };
-		757BC9631C1CA5790093AAA9 /* CRC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757BC9231C1CA5790093AAA9 /* CRC.swift */; };
+		757BC9601C1CA5790093AAA9 /* Checksum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757BC9231C1CA5790093AAA9 /* Checksum.swift */; };
+		757BC9611C1CA5790093AAA9 /* Checksum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757BC9231C1CA5790093AAA9 /* Checksum.swift */; };
+		757BC9621C1CA5790093AAA9 /* Checksum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757BC9231C1CA5790093AAA9 /* Checksum.swift */; };
+		757BC9631C1CA5790093AAA9 /* Checksum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757BC9231C1CA5790093AAA9 /* Checksum.swift */; };
 		757BC9681C1CA5790093AAA9 /* CSArrayType+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757BC9251C1CA5790093AAA9 /* CSArrayType+Extensions.swift */; };
 		757BC9691C1CA5790093AAA9 /* CSArrayType+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757BC9251C1CA5790093AAA9 /* CSArrayType+Extensions.swift */; };
 		757BC96A1C1CA5790093AAA9 /* CSArrayType+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 757BC9251C1CA5790093AAA9 /* CSArrayType+Extensions.swift */; };
@@ -377,7 +377,7 @@
 		757BC91D1C1CA5790093AAA9 /* Authenticator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Authenticator.swift; path = Sources/CryptoSwift/Authenticator.swift; sourceTree = SOURCE_ROOT; };
 		757BC91F1C1CA5790093AAA9 /* BytesSequence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BytesSequence.swift; path = Sources/CryptoSwift/BytesSequence.swift; sourceTree = SOURCE_ROOT; };
 		757BC9201C1CA5790093AAA9 /* ChaCha20.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChaCha20.swift; path = Sources/CryptoSwift/ChaCha20.swift; sourceTree = SOURCE_ROOT; };
-		757BC9231C1CA5790093AAA9 /* CRC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CRC.swift; path = Sources/CryptoSwift/CRC.swift; sourceTree = SOURCE_ROOT; };
+		757BC9231C1CA5790093AAA9 /* Checksum.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Checksum.swift; path = Sources/CryptoSwift/Checksum.swift; sourceTree = SOURCE_ROOT; };
 		757BC9251C1CA5790093AAA9 /* CSArrayType+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "CSArrayType+Extensions.swift"; path = "Sources/CryptoSwift/CSArrayType+Extensions.swift"; sourceTree = SOURCE_ROOT; };
 		757BC9261C1CA5790093AAA9 /* Generics.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Generics.swift; path = Sources/CryptoSwift/Generics.swift; sourceTree = SOURCE_ROOT; };
 		757BC9271C1CA5790093AAA9 /* Hash.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Hash.swift; path = Sources/CryptoSwift/Hash.swift; sourceTree = SOURCE_ROOT; };
@@ -519,8 +519,7 @@
 				75DB81A71CDC06B100ED181A /* Updatable.swift */,
 				75558FCB1D4BA93C00CF6C18 /* RandomAccessCryptor.swift */,
 				75CB93291C8F5EC60087740D /* BlockMode */,
-				757BC9231C1CA5790093AAA9 /* CRC.swift */,
-				757BC9251C1CA5790093AAA9 /* CSArrayType+Extensions.swift */,
+				757BC9231C1CA5790093AAA9 /* Checksum.swift */,
 				757BC9261C1CA5790093AAA9 /* Generics.swift */,
 				757BC9271C1CA5790093AAA9 /* Hash.swift */,
 				757BC9281C1CA5790093AAA9 /* HashProtocol.swift */,
@@ -539,6 +538,7 @@
 				757BC9361C1CA5790093AAA9 /* SHA2.swift */,
 				757BC93B1C1CA5790093AAA9 /* Utils.swift */,
 				757BC91B1C1CA5790093AAA9 /* Array+Extension.swift */,
+				757BC9251C1CA5790093AAA9 /* CSArrayType+Extensions.swift */,
 				756B575E1D5131A4001C0C72 /* Collection+Extension.swift */,
 				757BC9371C1CA5790093AAA9 /* String+Extension.swift */,
 				757BC92C1C1CA5790093AAA9 /* Int+Extension.swift */,
@@ -891,7 +891,7 @@
 				75482EA81CB329C1001F66A5 /* PBKDF2.swift in Sources */,
 				757BC90F1C1CA56A0093AAA9 /* Rabbit+Foundation.swift in Sources */,
 				757BC9691C1CA5790093AAA9 /* CSArrayType+Extensions.swift in Sources */,
-				757BC9611C1CA5790093AAA9 /* CRC.swift in Sources */,
+				757BC9611C1CA5790093AAA9 /* Checksum.swift in Sources */,
 				757BC9A11C1CA5790093AAA9 /* Poly1305.swift in Sources */,
 				75CB93451C8F603C0087740D /* CTR.swift in Sources */,
 				753881EC1CB06E390089101D /* NoPadding.swift in Sources */,
@@ -957,7 +957,7 @@
 				757BC9061C1CA56A0093AAA9 /* ChaCha20+Foundation.swift in Sources */,
 				75482EA71CB329C1001F66A5 /* PBKDF2.swift in Sources */,
 				757BC9681C1CA5790093AAA9 /* CSArrayType+Extensions.swift in Sources */,
-				757BC9601C1CA5790093AAA9 /* CRC.swift in Sources */,
+				757BC9601C1CA5790093AAA9 /* Checksum.swift in Sources */,
 				757BC9A01C1CA5790093AAA9 /* Poly1305.swift in Sources */,
 				75CB93441C8F603C0087740D /* CTR.swift in Sources */,
 				757BC9BC1C1CA5790093AAA9 /* UInt64+Extension.swift in Sources */,
@@ -1041,7 +1041,7 @@
 				75482EAA1CB329C1001F66A5 /* PBKDF2.swift in Sources */,
 				757BC9081C1CA56A0093AAA9 /* ChaCha20+Foundation.swift in Sources */,
 				757BC96A1C1CA5790093AAA9 /* CSArrayType+Extensions.swift in Sources */,
-				757BC9621C1CA5790093AAA9 /* CRC.swift in Sources */,
+				757BC9621C1CA5790093AAA9 /* Checksum.swift in Sources */,
 				757BC9A21C1CA5790093AAA9 /* Poly1305.swift in Sources */,
 				75CB93461C8F603C0087740D /* CTR.swift in Sources */,
 				753881EE1CB06E390089101D /* NoPadding.swift in Sources */,
@@ -1107,7 +1107,7 @@
 				75482EA91CB329C1001F66A5 /* PBKDF2.swift in Sources */,
 				757BC9111C1CA56A0093AAA9 /* Rabbit+Foundation.swift in Sources */,
 				757BC96B1C1CA5790093AAA9 /* CSArrayType+Extensions.swift in Sources */,
-				757BC9631C1CA5790093AAA9 /* CRC.swift in Sources */,
+				757BC9631C1CA5790093AAA9 /* Checksum.swift in Sources */,
 				757BC9A31C1CA5790093AAA9 /* Poly1305.swift in Sources */,
 				75CB93471C8F603C0087740D /* CTR.swift in Sources */,
 				753881ED1CB06E390089101D /* NoPadding.swift in Sources */,

+ 3 - 3
CryptoSwiftTests/Access.swift

@@ -13,9 +13,9 @@ class Access: XCTestCase {
     let cipher = try! AES(key: Array<UInt8>(hex: "b1b2b3b3b3b3b3b3b1b2b3b3b3b3b3b3"))
     let authenticator = Authenticator.HMAC(key: Array<UInt8>(hex: "b1b2b3b3b3b3b3b3b1b2b3b3b3b3b3b3"), variant: .sha1)
 
-    func testCRC() {
-        let _ = CRC.crc32([1,2,3])
-        let _ = CRC.crc16([1,2,3])
+    func testChecksum() {
+        let _ = Checksum.crc32([1,2,3])
+        let _ = Checksum.crc16([1,2,3])
     }
 
     func testHash() {

+ 1 - 1
CryptoSwiftTests/HashTests.swift

@@ -131,7 +131,7 @@ final class CryptoSwiftTests: XCTestCase {
     }
     
     func testCRC16() {
-        let result = CRC.crc16([49,50,51,52,53,54,55,56,57] as Array<UInt8>)
+        let result = Checksum.crc16([49,50,51,52,53,54,55,56,57] as Array<UInt8>)
         XCTAssert(result == 0xBB3D, "CRC16 failed")
     }
     

+ 2 - 2
Sources/CryptoSwift/CSArrayType+Extensions.swift

@@ -48,11 +48,11 @@ public extension CSArrayType where Iterator.Element == UInt8 {
     }
     
     public func crc32(seed: UInt32? = nil, reflect : Bool = true) -> UInt32 {
-        return CRC.crc32(cs_arrayValue(), seed: seed, reflect: reflect)
+        return Checksum.crc32(cs_arrayValue(), seed: seed, reflect: reflect)
     }
     
     public func crc16(seed: UInt16? = nil) -> UInt16 {
-        return CRC.crc16(cs_arrayValue(), seed: seed)
+        return Checksum.crc16(cs_arrayValue(), seed: seed)
     }
     
     public func encrypt(cipher: Cipher) throws -> [Iterator.Element] {

+ 7 - 7
Sources/CryptoSwift/CRC.swift → Sources/CryptoSwift/Checksum.swift

@@ -1,12 +1,12 @@
 //
-//  CRC.swift
+//  Checksum.swift
 //  CryptoSwift
 //
 //  Created by Marcin Krzyzanowski on 25/08/14.
 //  Copyright (c) 2014 Marcin Krzyzanowski. All rights reserved.
 //
 
-public final class CRC {
+public final class Checksum {
     private static let table32:Array<UInt32> = [0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
         0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
         0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
@@ -78,7 +78,7 @@ public final class CRC {
         for chunk in BytesSequence(chunkSize: 256, data: message) {
             for b in chunk {
                 let idx = Int((crc ^ UInt32(reflect ? b : reversed(b))) & 0xff)
-                crc = (crc >> 8) ^ CRC.table32[idx]
+                crc = (crc >> 8) ^ Checksum.table32[idx]
             }
         }
         return (reflect ? crc : reversed(crc)) ^ 0xffffffff
@@ -88,7 +88,7 @@ public final class CRC {
         var crc:UInt16 = seed != nil ? seed! : 0x0000
         for chunk in BytesSequence(chunkSize: 256, data: message) {
             for b in chunk {
-                crc = (crc >> 8) ^ CRC.table16[Int((crc ^ UInt16(b)) & 0xFF)]
+                crc = (crc >> 8) ^ Checksum.table16[Int((crc ^ UInt16(b)) & 0xFF)]
             }
         }
         return crc
@@ -96,12 +96,12 @@ public final class CRC {
 }
 
 //MARK: Public interface
-public extension CRC {
+public extension Checksum {
     static func crc32(_ message:Array<UInt8>, seed: UInt32? = nil, reflect : Bool = true) -> UInt32 {
-        return CRC().crc32(message, seed: seed, reflect: reflect)
+        return Checksum().crc32(message, seed: seed, reflect: reflect)
     }
 
     static func crc16(_ message:Array<UInt8>, seed: UInt16? = nil) -> UInt16 {
-        return CRC().crc16(message, seed: seed)
+        return Checksum().crc16(message, seed: seed)
     }
 }

+ 2 - 2
Sources/CryptoSwift/Foundation/Data+Extension.swift

@@ -61,12 +61,12 @@ extension Data {
     }
 
     public func crc32(seed: UInt32? = nil, reflect : Bool = true) -> Data? {
-        let result = CRC.crc32(self.bytes, seed: seed, reflect: reflect)
+        let result = Checksum.crc32(self.bytes, seed: seed, reflect: reflect)
         return Data(bytes: result.bytes())
     }
 
     public func crc16(seed: UInt16? = nil) -> Data? {
-        let result = CRC.crc16(self.bytes, seed: seed)
+        let result = Checksum.crc16(self.bytes, seed: seed)
         return Data(bytes: result.bytes())
     }