Skip to content

Commit

Permalink
[Add] tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Deadlyelder committed Jan 4, 2022
1 parent e72ed44 commit b990466
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
17 changes: 17 additions & 0 deletions blake2/blake2/blake2utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,20 @@
//

import Foundation
import CommonCrypto

extension String {
public func unhexlify() -> [UInt8] {
var pos = startIndex
return (0..<count/2).compactMap { _ in
defer { pos = index(pos, offsetBy: 2) }
return UInt8(self[pos...index(after: pos)], radix: 16)
}
}
}

extension Collection where Iterator.Element == UInt8 {
public func hexDescription() -> String {
return self.map({ String(format: "%02x", $0) }).joined()
}
}
15 changes: 15 additions & 0 deletions blake2/blake2Tests/blake2Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ class blake2Tests: XCTestCase {
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}

func test1() {
let calc = Blake2.hash(data: [0x61, 0x62, 0x63])
print("\(calc.hexDescription())")
let expected:[UInt8] = [
0xBA, 0x80, 0xA5, 0x3F, 0x98, 0x1C, 0x4D, 0x0D, 0x6A, 0x27, 0x97, 0xB6, 0x9F, 0x12, 0xF6, 0xE9,
0x4C, 0x21, 0x2F, 0x14, 0x68, 0x5A, 0xC4, 0xB7, 0x4B, 0x12, 0xBB, 0x6F, 0xDB, 0xFF, 0xA2, 0xD1,
0x7D, 0x87, 0xC5, 0x39, 0x2A, 0xAB, 0x79, 0x2D, 0xC2, 0x52, 0xD5, 0xDE, 0x45, 0x33, 0xCC, 0x95,
0x18, 0xD3, 0x8A, 0xA8, 0xDB, 0xF1, 0x92, 0x5A, 0xB9, 0x23, 0x86, 0xED, 0xD4, 0x00, 0x99, 0x23
]
XCTAssertEqual(calc.count, 64)
for i in 0..<64 {
XCTAssertEqual(calc[i], expected[i])
}
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
Expand Down

0 comments on commit b990466

Please sign in to comment.