Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from qutheory/cryptokitten-update
update to live cryptokitten
- Loading branch information
Showing
10 changed files
with
430 additions
and
384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
swift: | ||
config_file: .swiftlint.yml | ||
fail_on_violations: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
disabled_rules: | ||
opt_in_rules: | ||
- missing_docs | ||
included: | ||
excluded: | ||
- Packages | ||
- Sources/Vapor/Core/Generated.swift | ||
- Sources/Generator | ||
- Sources/Generator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,40 @@ | ||
import HMAC | ||
import SHA1 | ||
import SHA2 | ||
|
||
/** | ||
Create SHA1 + HMAC hashes with the | ||
Create SHA + HMAC hashes with the | ||
Hash class by applying this driver. | ||
*/ | ||
public class SHAHasher: HashDriver { | ||
public class SHA2Hasher: HashDriver { | ||
|
||
var variant: Variant | ||
|
||
init(variant: Variant) { | ||
self.variant = variant | ||
} | ||
|
||
public enum Variant { | ||
case sha256 | ||
case sha384 | ||
case sha512 | ||
} | ||
|
||
public func hash(message: String, key: String) -> String { | ||
let keyBuff = key.data.bytes | ||
let msgBuff = message.data.bytes | ||
|
||
var msgBuff = [UInt8]() | ||
msgBuff += message.utf8 | ||
let hashed: [Byte] | ||
|
||
var keyBuff = [UInt8]() | ||
keyBuff += key.utf8 | ||
switch variant { | ||
case .sha256: | ||
hashed = HMAC<SHA2<SHA256>>.authenticate(msgBuff, withKey: keyBuff) | ||
case .sha384: | ||
hashed = HMAC<SHA2<SHA384>>.authenticate(msgBuff, withKey: keyBuff) | ||
case .sha512: | ||
hashed = HMAC<SHA2<SHA512>>.authenticate(msgBuff, withKey: keyBuff) | ||
} | ||
|
||
let hmac = HMAC.authenticate(key: keyBuff, message: msgBuff, variant: SHA1.self) | ||
return hmac.toHexString() | ||
return hashed.toHexString() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.