Skip to content

Commit 2252dcf

Browse files
committed
Add conversion from and to hex for SRPKey
1 parent 92c6014 commit 2252dcf

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Sources/SRP/keys.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@ import BigNum
22

33
/// Wrapper for keys used by SRP
44
public struct SRPKey {
5-
public var bytes: [UInt8] { number.bytes }
65
public let number: BigNum
7-
6+
public var bytes: [UInt8] { number.bytes }
7+
public var hex: String { number.hex }
8+
89
public init(_ bytes: [UInt8]) {
910
self.number = BigNum(bytes: bytes)
1011
}
1112

1213
public init(_ number: BigNum) {
1314
self.number = number
1415
}
16+
17+
public init?(hex: String) {
18+
guard let number = BigNum(hex: hex) else { return nil }
19+
self.number = number
20+
}
1521
}
1622

1723
extension SRPKey: Equatable { }

0 commit comments

Comments
 (0)