@@ -15,18 +15,6 @@ import Crypto
1515/// - https://tools.ietf.org/html/rfc5054
1616///
1717public struct SRPClient < H: HashFunction > {
18- /// Errors thrown by SRPClient
19- public enum Error : Swift . Error {
20- /// the key returned by server is invalid, in that either it modulo N is zero or the hash(A,B) is zero
21- case nullServerKey
22- /// server verification code was wrong
23- case invalidServerCode
24- /// you called verifyServerCode without a verification key
25- case requiresVerificationKey
26- /// client key is invalid
27- case invalidClientKey
28- }
29-
3018 /// configuration. This needs to be the same as the server configuration
3119 public let configuration : SRPConfiguration < H >
3220
@@ -86,7 +74,7 @@ public struct SRPClient<H: HashFunction> {
8674 // get out version of server proof
8775 let HAMS = SRP< H> . calculateSimpleServerVerification( clientPublicKey: clientKeys. public, clientProof: clientProof, sharedSecret: sharedSecret)
8876 // is it the same
89- guard serverProof == HAMS else { throw Error . invalidServerCode }
77+ guard serverProof == HAMS else { throw SRPClientError . invalidServerCode }
9078 }
9179
9280 /// calculate proof of shared secret to send to server
@@ -116,7 +104,7 @@ public struct SRPClient<H: HashFunction> {
116104 // get out version of server proof
117105 let HAMK = SRP< H> . calculateServerVerification( clientPublicKey: clientKeys. public, clientProof: clientProof, sharedSecret: hashSharedSecret)
118106 // is it the same
119- guard serverProof == HAMK else { throw Error . invalidServerCode }
107+ guard serverProof == HAMK else { throw SRPClientError . invalidServerCode }
120108 }
121109
122110 /// Generate salt and password verifier from username and password. When creating your user instead of passing your password to the server, you
@@ -136,12 +124,12 @@ public struct SRPClient<H: HashFunction> {
136124extension SRPClient {
137125 /// return shared secret given the username, password, B value and salt from the server
138126 func calculateSharedSecret( message: [ UInt8 ] , salt: [ UInt8 ] , clientKeys: SRPKeyPair , serverPublicKey: SRPKey ) throws -> BigNum {
139- guard serverPublicKey. number % configuration. N != BigNum ( 0 ) else { throw Error . nullServerKey }
127+ guard serverPublicKey. number % configuration. N != BigNum ( 0 ) else { throw SRPClientError . nullServerKey }
140128
141129 // calculate u = H(clientPublicKey | serverPublicKey)
142130 let u = SRP< H> . calculateU( clientPublicKey: clientKeys. public. bytes, serverPublicKey: serverPublicKey. bytes, pad: configuration. sizeN)
143131
144- guard u != 0 else { throw Error . nullServerKey }
132+ guard u != 0 else { throw SRPClientError . nullServerKey }
145133
146134 let x = BigNum ( bytes: [ UInt8] ( H . hash ( data: salt + H. hash ( data: message) ) ) )
147135
0 commit comments