Skip to content

Commit

Permalink
Set padding in SRPKey(hex:)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Oct 31, 2024
1 parent c4341f0 commit 7d2ca05
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/SRP/keys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public struct SRPKey {
}

/// Initialize with a hex string
@inlinable public init?(hex: String, padding: Int = 0) {
@inlinable public init?(hex: String, padding: Int? = nil) {
guard let number = BigNum(hex: hex) else { return nil }
self.number = number
self.padding = padding
self.padding = padding ?? (hex.count + 1) / 2
}

/// Initialize with a BigNum
Expand Down
7 changes: 7 additions & 0 deletions Tests/SRPTests/SRPTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import Crypto
import XCTest

final class SRPTests: XCTestCase {
func testHexKeyConversion() {
let hex = "0004f6789b"
XCTAssertEqual(hex, SRPKey(hex: hex)?.hex)
let hex2 = "4f6789b"
XCTAssertEqual("04f6789b", SRPKey(hex: hex2)?.hex)
}

func testSRPSharedSecret() {
let username = "adamfowler"
let password = "testpassword"
Expand Down

0 comments on commit 7d2ca05

Please sign in to comment.