From c318b79e7a5919d88de80abcda13b98a417b9e90 Mon Sep 17 00:00:00 2001 From: Tanner Nelson Date: Thu, 4 Aug 2016 17:07:28 -0400 Subject: [PATCH] hash --- couscous.yml | 3 +++ guide/hash.md | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 guide/hash.md diff --git a/couscous.yml b/couscous.yml index 4ca08f61..1224eb01 100644 --- a/couscous.yml +++ b/couscous.yml @@ -56,6 +56,9 @@ menu: guide-validation: text: Validation relativeUrl: guide/validation.html + guide-hash: + text: Hash + relativeUrl: guide/hash.html routing: name: Routing items: diff --git a/guide/hash.md b/guide/hash.md new file mode 100644 index 00000000..b28bd299 --- /dev/null +++ b/guide/hash.md @@ -0,0 +1,36 @@ +--- +currentMenu: guide-hash +--- + +# Hash + +Vapor makes hashing strings easy. + +## Example + +To hash a string, use the `hash` class on `Droplet`. + +```swift +let hashed = drop.hash.make("vapor") +``` + +## SHA2Hasher + +By default, Vapor uses a SHA2Hasher with 256 bits. You can change this by giving the `Droplet` a different hasher. + +```swift +let sha512 = SHA2Hasher(variant: .sha512) + +let drop = Droplet(hash: sha512) +``` + +### Protocol + +You can also create your own hasher. You just need to conform to the `Hash` protocol. + +```swift +public protocol Hash: class { + var key: String { get set } + func make(_ string: String) -> String +} +```