-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypto.mbt
More file actions
25 lines (22 loc) · 873 Bytes
/
Copy pathcrypto.mbt
File metadata and controls
25 lines (22 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// The primitives go-zero's middlewares name, bound to `mooncrypt`.
//
// Nothing is implemented here. Every line hands off; what this file carries is
// the binding, so the auth and discovery layers ask for a digest rather than
// restating which package it comes from on every call.
///|
/// SHA-256 (FIPS 180-4), which the signature middleware and the Redis-backed
/// registry both hash with.
pub fn sha256(msg : Bytes) -> Bytes {
@sha2.hash(msg[:])
}
///|
/// HMAC-SHA256 (RFC 2104), which signs JWTs and the request signatures.
pub fn hmac_sha256(key : Bytes, msg : Bytes) -> Bytes {
@hmac.mac(key[:], msg[:], () => @sha2.Hasher::new())
}
///|
/// Compare two byte strings in time that does not depend on where they first
/// differ (← go-zero's `subtle.ConstantTimeCompare`).
pub fn constant_time_eq(a : Bytes, b : Bytes) -> Bool {
@spec.eq(a[:], b[:])
}