Ver código fonte

Changed NSError to custom private Error enum in String.streamHexBytes because NSError was throwing "error: use of unresolved identifier 'NSError'" in travis ci tests

jose 8 anos atrás
pai
commit
c86ed3e73b
1 arquivos alterados com 5 adições e 2 exclusões
  1. 5 2
      Sources/CryptoSwift/String+Extension.swift

+ 5 - 2
Sources/CryptoSwift/String+Extension.swift

@@ -84,7 +84,7 @@ extension String {
     
     
     // Allows str.hexToBytes() and Array<UInt8>(hex: str) to share the same code
     // Allows str.hexToBytes() and Array<UInt8>(hex: str) to share the same code
     // Old functionality returns a blank array upon encountering a non hex character so this method must throw in order to replicate that in methods relying on this method. (ex. "ffn" should return [] instead of [255])
     // Old functionality returns a blank array upon encountering a non hex character so this method must throw in order to replicate that in methods relying on this method. (ex. "ffn" should return [] instead of [255])
-    // Consider switching NSError to custom Error enum
+    // Changed NSError to custom Error enum
     public func streamHexBytes(_ block:(UInt8)->Void) throws{
     public func streamHexBytes(_ block:(UInt8)->Void) throws{
         var buffer:UInt8?
         var buffer:UInt8?
         var skip = hasPrefix("0x") ? 2 : 0
         var skip = hasPrefix("0x") ? 2 : 0
@@ -94,7 +94,7 @@ extension String {
                 continue
                 continue
             }
             }
             guard let value = String.unicodeHexMap[char] else {
             guard let value = String.unicodeHexMap[char] else {
-                throw NSError(domain: "com.krzyzanowskim.CryptoSwift.hexParseError", code: 0, userInfo: nil)
+                throw HexError.invalidCharacter
             }
             }
             if let b = buffer {
             if let b = buffer {
                 block(b << 4 | value)
                 block(b << 4 | value)
@@ -106,4 +106,7 @@ extension String {
         if let b = buffer{block(b)}
         if let b = buffer{block(b)}
     }
     }
     
     
+    private enum HexError:Error {
+        case invalidCharacter
+    }
 }
 }