From 79ac24af271ee86fa9668ed0c3471aa9f1dfcc09 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sat, 23 Sep 2017 15:14:30 +0200 Subject: [PATCH] Add testes for the padding functions --- README.md | 14 ++++++++++++++ SodiumTests/ReadmeTests.swift | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/README.md b/README.md index 5ee1c2c..e0515b5 100644 --- a/README.md +++ b/README.md @@ -327,6 +327,20 @@ let secret2 = "Secret key".data(using:.utf8)! let equality = sodium.utils.equals(secret1, secret2) ``` +Padding +------- + +```swift +let sodium = Sodium() +var data = "test".toData()! + +// make data.count a multiple of 16 +sodium.utils.pad(data: &data, blockSize: 16)! + +// restore original size +sodium.utils.unpad(data: &data, blockSize: 16)! +``` + Constant-time hexadecimal encoding ---------------------------------- diff --git a/SodiumTests/ReadmeTests.swift b/SodiumTests/ReadmeTests.swift index efe0f46..26a475c 100644 --- a/SodiumTests/ReadmeTests.swift +++ b/SodiumTests/ReadmeTests.swift @@ -254,4 +254,15 @@ class ReadmeTests : XCTestCase { XCTAssertEqual(data2, "data".toData()) XCTAssertEqual(data3, "data".toData()) } + + func testPadding() { + let sodium = Sodium() + var data = "test".toData()! + + // make data.count a multiple of 16 + sodium.utils.pad(data: &data, blockSize: 16)! + + // restore original size + sodium.utils.unpad(data: &data, blockSize: 16)! + } }