Marcin Krzyżanowski před 9 roky
rodič
revize
d5fcc52591

+ 6 - 2
Sources/CryptoSwift/MD5.swift

@@ -6,7 +6,7 @@
 //  Copyright (c) 2014 Marcin Krzyzanowski. All rights reserved.
 //  Copyright (c) 2014 Marcin Krzyzanowski. All rights reserved.
 //
 //
 
 
-final class MD5: DigestType  {
+public class MD5: DigestType  {
     static let blockSize:Int = 64
     static let blockSize:Int = 64
     static let digestSize:Int = 16 // 128 / 8
     static let digestSize:Int = 16 // 128 / 8
     fileprivate static let hashInitialValue:Array<UInt32> = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476]
     fileprivate static let hashInitialValue:Array<UInt32> = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476]
@@ -39,6 +39,10 @@ final class MD5: DigestType  {
                        0x6fa87e4f,0xfe2ce6e0,0xa3014314,0x4e0811a1,
                        0x6fa87e4f,0xfe2ce6e0,0xa3014314,0x4e0811a1,
                        0xf7537e82,0xbd3af235,0x2ad7d2bb,0xeb86d391]
                        0xf7537e82,0xbd3af235,0x2ad7d2bb,0xeb86d391]
 
 
+    public init() {
+        
+    }
+
     func calculate(for bytes: Array<UInt8>) -> Array<UInt8> {
     func calculate(for bytes: Array<UInt8>) -> Array<UInt8> {
         do {
         do {
             return try self.update(withBytes: bytes, isLast: true)
             return try self.update(withBytes: bytes, isLast: true)
@@ -102,7 +106,7 @@ final class MD5: DigestType  {
 }
 }
 
 
 extension MD5: Updatable {
 extension MD5: Updatable {
-    func update<T: Sequence>(withBytes bytes: T, isLast: Bool = false) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
+    public func update<T: Sequence>(withBytes bytes: T, isLast: Bool = false) throws -> Array<UInt8> where T.Iterator.Element == UInt8 {
         let prevAccumulatedLength = self.accumulated.count
         let prevAccumulatedLength = self.accumulated.count
         self.accumulated += bytes
         self.accumulated += bytes
         self.accumulatedLength += self.accumulated.count - prevAccumulatedLength //avoid Array(bytes).count
         self.accumulatedLength += self.accumulated.count - prevAccumulatedLength //avoid Array(bytes).count

+ 4 - 2
Tests/CryptoSwiftTests/Access.swift

@@ -20,13 +20,15 @@ class Access: XCTestCase {
         let _ = Checksum.crc16([1,2,3])
         let _ = Checksum.crc16([1,2,3])
     }
     }
 
 
-    func testHash() {
+    func testDigest() {
         let _ = Digest.md5([1,2,3])
         let _ = Digest.md5([1,2,3])
         let _ = Digest.sha1([1,2,3])
         let _ = Digest.sha1([1,2,3])
         let _ = Digest.sha224([1,2,3])
         let _ = Digest.sha224([1,2,3])
         let _ = Digest.sha256([1,2,3])
         let _ = Digest.sha256([1,2,3])
         let _ = Digest.sha384([1,2,3])
         let _ = Digest.sha384([1,2,3])
         let _ = Digest.sha512([1,2,3])
         let _ = Digest.sha512([1,2,3])
+
+        let _ = MD5()
     }
     }
 
 
     func testArrayExtension() {
     func testArrayExtension() {
@@ -225,7 +227,7 @@ class Access: XCTestCase {
     
     
     static let allTests =  [
     static let allTests =  [
         ("testChecksum", testChecksum),
         ("testChecksum", testChecksum),
-        ("testHash", testHash),
+        ("testDigest", testDigest),
         ("testArrayExtension", testArrayExtension),
         ("testArrayExtension", testArrayExtension),
         ("testCollectionExtension", testCollectionExtension),
         ("testCollectionExtension", testCollectionExtension),
         ("testStringExtension", testStringExtension),
         ("testStringExtension", testStringExtension),