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; + } }