From 127ffd31971b7261cebc80cb4a62c30754c05467 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Fri, 16 Aug 2019 09:09:11 -0400 Subject: [PATCH] signCookie --- lib/src/cookie_signer.dart | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/src/cookie_signer.dart b/lib/src/cookie_signer.dart index 64747811..653a8ebb 100644 --- a/lib/src/cookie_signer.dart +++ b/lib/src/cookie_signer.dart @@ -27,5 +27,18 @@ class CookieSigner { } } - void signCookie(Cookie cookie) {} + /// **Overwrites** the value of a [cookie] with one that is signed + /// with the [hmac]. + /// + /// The signature is: + /// `base64Url(cookie.value) + "." + base64Url(sig)` + /// + /// Where `sig` is the cookie's value, signed with the [hmac]. + void signCookie(Cookie cookie) { + // base64Url(cookie) + "." + base64Url(sig) + var encodedCookie = base64Url.encode(cookie.value.codeUnits); + var sigBytes = hmac.convert(cookie.value.codeUnits).bytes; + var sig = base64Url.encode(sigBytes); + cookie.value = encodedCookie + '.' + sig; + } }