Skip to content

Commit

Permalink
Merge pull request #26 from vapor/crypt-alpha
Browse files Browse the repository at this point in the history
crypto alpha
  • Loading branch information
tanner0101 authored Feb 17, 2017
2 parents 582acf8 + e12052e commit b68697f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import PackageDescription
let package = Package(
name: "JWT",
dependencies: [
.Package(url: "https://github.com/vapor/crypto.git", majorVersion: 1),
.Package(url: "https://github.com/vapor/json.git", majorVersion: 1),
.Package(url: "https://github.com/vapor/crypto.git", Version(2,0,0, prereleaseIdentifiers: ["alpha"])),
.Package(url: "https://github.com/vapor/json.git", Version(2,0,0, prereleaseIdentifiers: ["alpha"]))
],
exclude: [
"Playground"
Expand Down
2 changes: 1 addition & 1 deletion Sources/JWT/Encodings/Base64Encoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public struct Base64Encoding: Encoding {
}

public func decode(_ base64Encoded: String) throws -> Bytes {
return base64Encoded.bytes.base64Decoded
return base64Encoded.makeBytes().base64Decoded
}
}
2 changes: 1 addition & 1 deletion Sources/JWT/Encodings/Base64URLEncoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public struct Base64URLEncoding: Encoding {
let data = Data(base64Encoded: base64Encoded) else {
throw JWTError.decoding
}
return try data.makeBytes()
return data.makeBytes()
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/JWT/JWT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public struct JWT {

let encoded = try [headers, payload].map(encoding.encode)
let message = encoded.joined(separator: JWT.separator)
let bytes = try signer.sign(message: message.bytes)
let bytes = try signer.sign(message: message.makeBytes())
signature = try encoding.encode(bytes)
}

Expand Down Expand Up @@ -115,7 +115,7 @@ extension JWT: SignatureVerifiable {
return try [headers, payload]
.map(encoding.encode)
.joined(separator: JWT.separator)
.bytes
.makeBytes()
}

public func createSignature() throws -> Bytes {
Expand Down
2 changes: 1 addition & 1 deletion Tests/JWTTests/JWTTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct TildeSigner: Signer {

struct PeriodToCommaEncoding: Encoding {
func decode(_ string: String) throws -> Bytes {
return string.bytes.map {
return string.makeBytes().map {
switch $0 {
case 44: return 46
default: return $0
Expand Down
13 changes: 7 additions & 6 deletions Tests/JWTTests/SignerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ final class SignerTests: XCTestCase {
func testUnsigned() throws {
let signer = Unsigned()
XCTAssertEqual(signer.name, "none")
XCTAssertEqual(try signer.sign(message: "a".bytes), [])
try signer.verify(signature: "a".bytes, message: "b".bytes)
XCTAssertEqual(try signer.sign(message: "a".makeBytes()), [])
try signer.verify(signature: "a".makeBytes(), message: "b".makeBytes())
}

func checkHMACSigner(
createSigner: (Bytes) -> HMACSigner,
name: String,
message: Bytes = "message".bytes,
key: Bytes = "secret".bytes,
message: Bytes = "message".makeBytes(),
key: Bytes = "secret".makeBytes(),
signed: String,
file: StaticString = #file,
line: UInt = #line
Expand Down Expand Up @@ -62,13 +62,14 @@ final class SignerTests: XCTestCase {
publicKey: String,
file: StaticString = #file,
line: UInt = #line

) throws {
let signer = try createSigner(try encoder.decode(privateKey))
let verifier = try createSigner(try encoder.decode(publicKey))
XCTAssertEqual(signer.name, name, file: file, line: line)

let signature = try signer.sign(message: message.bytes)
try verifier.verify(signature: signature, message: message.bytes)
let signature = try signer.sign(message: message.makeBytes())
try verifier.verify(signature: signature, message: message.makeBytes())
}

func testES256() throws {
Expand Down

0 comments on commit b68697f

Please sign in to comment.