Skip to content

Commit c86ed3e

Browse files
Changed NSError to custom private Error enum in String.streamHexBytes because NSError was throwing "error: use of unresolved identifier 'NSError'" in travis ci tests
1 parent c8476fa commit c86ed3e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Sources/CryptoSwift/String+Extension.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ extension String {
8484

8585
// Allows str.hexToBytes() and Array<UInt8>(hex: str) to share the same code
8686
// 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])
87-
// Consider switching NSError to custom Error enum
87+
// Changed NSError to custom Error enum
8888
public func streamHexBytes(_ block:(UInt8)->Void) throws{
8989
var buffer:UInt8?
9090
var skip = hasPrefix("0x") ? 2 : 0
@@ -94,7 +94,7 @@ extension String {
9494
continue
9595
}
9696
guard let value = String.unicodeHexMap[char] else {
97-
throw NSError(domain: "com.krzyzanowskim.CryptoSwift.hexParseError", code: 0, userInfo: nil)
97+
throw HexError.invalidCharacter
9898
}
9999
if let b = buffer {
100100
block(b << 4 | value)
@@ -106,4 +106,7 @@ extension String {
106106
if let b = buffer{block(b)}
107107
}
108108

109+
private enum HexError:Error {
110+
case invalidCharacter
111+
}
109112
}

0 commit comments

Comments
 (0)