Преглед изворни кода

Seed added to string extensions, default values added

Rich Lowenberg пре 10 година
родитељ
комит
4e47769214
2 измењених фајлова са 6 додато и 6 уклоњено
  1. 2 2
      CryptoSwift/Foundation/NSData+Extension.swift
  2. 4 4
      CryptoSwift/String+Extension.swift

+ 2 - 2
CryptoSwift/Foundation/NSData+Extension.swift

@@ -60,12 +60,12 @@ extension NSData {
         return NSData.withBytes(result)
     }
 
-    public func crc32(seed: UInt32?) -> NSData? {
+    public func crc32(seed: UInt32? = nil) -> NSData? {
         let result = Hash.crc32(self.arrayOfBytes(), seed: seed).calculate()
         return NSData.withBytes(result)
     }
 
-    public func crc16(seed: UInt16?) -> NSData? {
+    public func crc16(seed: UInt16? = nil) -> NSData? {
         let result = Hash.crc16(self.arrayOfBytes(), seed: seed).calculate()
         return NSData.withBytes(result)
     }

+ 4 - 4
CryptoSwift/String+Extension.swift

@@ -33,12 +33,12 @@ extension String {
         return self.utf8.lazy.map({ $0 as UInt8 }).sha512().toHexString()
     }
 
-    public func crc32() -> String {
-        return self.utf8.lazy.map({ $0 as UInt8 }).crc32().toHexString()
+    public func crc32(seed: UInt32? = nil) -> String {
+        return self.utf8.lazy.map({ $0 as UInt8 }).crc32(seed).toHexString()
     }
 
-    public func crc16() -> String {
-        return self.utf8.lazy.map({ $0 as UInt8 }).crc16().toHexString()
+    public func crc16(seed: UInt16? = nil) -> String {
+        return self.utf8.lazy.map({ $0 as UInt8 }).crc16(seed).toHexString()
     }
 
     public func encrypt(cipher: Cipher) throws -> [UInt8] {