11//
22// Crypto.swift
3- //
3+ //
44//
55// Created by Andrew Barba on 2/8/23.
66//
@@ -13,15 +13,18 @@ public enum Crypto {}
1313
1414extension Crypto {
1515
16- public static func hash< T> ( _ input: String , using hash: T . Type ) -> T . Digest where T: HashFunction {
16+ public static func hash< T> ( _ input: String , using hash: T . Type ) -> T . Digest
17+ where T: HashFunction {
1718 return T . hash ( data: Data ( input. utf8) )
1819 }
1920
20- public static func hash< T> ( _ input: [ UInt8 ] , using hash: T . Type ) -> T . Digest where T: HashFunction {
21+ public static func hash< T> ( _ input: [ UInt8 ] , using hash: T . Type ) -> T . Digest
22+ where T: HashFunction {
2123 return T . hash ( data: Data ( input) )
2224 }
2325
24- public static func hash< T> ( _ input: Data , using hash: T . Type ) -> T . Digest where T: HashFunction {
26+ public static func hash< T> ( _ input: Data , using hash: T . Type ) -> T . Digest
27+ where T: HashFunction {
2528 return T . hash ( data: input)
2629 }
2730
@@ -92,7 +95,9 @@ extension Crypto {
9295 }
9396 }
9497
95- public static func verify( _ input: String , signature: Data , secret: String , using hash: Hash ) -> Bool {
98+ public static func verify(
99+ _ input: String , signature: Data , secret: String , using hash: Hash
100+ ) -> Bool {
96101 let computed = code ( for: input, secret: secret, using: hash)
97102 return computed. toHexString ( ) == signature. toHexString ( )
98103 }
@@ -109,7 +114,9 @@ extension Crypto {
109114 case p521
110115 }
111116
112- public static func signature( for input: String , secret: String , using algorithm: Algorithm ) throws -> Data {
117+ public static func signature( for input: String , secret: String , using algorithm: Algorithm )
118+ throws -> Data
119+ {
113120 switch algorithm {
114121 case . p256:
115122 let pk = try P256 . Signing. PrivateKey ( pemRepresentation: secret)
@@ -123,7 +130,9 @@ extension Crypto {
123130 }
124131 }
125132
126- public static func verify( _ input: String , signature: Data , key: String , using algorithm: Algorithm ) throws -> Bool {
133+ public static func verify(
134+ _ input: String , signature: Data , key: String , using algorithm: Algorithm
135+ ) throws -> Bool {
127136 switch algorithm {
128137 case . p256:
129138 let publicKey = try P256 . Signing. PublicKey ( pemRepresentation: key)
@@ -154,7 +163,7 @@ extension DataProtocol {
154163 }
155164
156165 public func toHexString( ) -> String {
157- return reduce ( " " ) { $0 + String( format: " %02x " , $1) }
166+ return reduce ( " " ) { $0 + String( format: " %02x " , $1) }
158167 }
159168}
160169
@@ -168,7 +177,7 @@ extension Digest {
168177 }
169178
170179 public func toHexString( ) -> String {
171- return reduce ( " " ) { $0 + String( format: " %02x " , $1) }
180+ return reduce ( " " ) { $0 + String( format: " %02x " , $1) }
172181 }
173182}
174183
@@ -182,7 +191,7 @@ extension HashedAuthenticationCode {
182191 }
183192
184193 public func toHexString( ) -> String {
185- return reduce ( " " ) { $0 + String( format: " %02x " , $1) }
194+ return reduce ( " " ) { $0 + String( format: " %02x " , $1) }
186195 }
187196}
188197
@@ -192,6 +201,6 @@ extension Array where Element == UInt8 {
192201 }
193202
194203 public func toHexString( ) -> String {
195- return reduce ( " " ) { $0 + String( format: " %02x " , $1) }
204+ return reduce ( " " ) { $0 + String( format: " %02x " , $1) }
196205 }
197206}
0 commit comments