rastrillo / idear Public

Clone
git clone https://amadan.net/rastrillo/idear

Plain git — no account needed to clone.

Download

Download this file

1package idear
2
3import (
4 "crypto/rand"
5 "crypto/sha256"
6 "encoding/hex"
7)
8
9// newToken mints an invitation credential: 32 bytes of crypto/rand,
10// hex-encoded (64 characters). The plaintext this returns exists only
11// in Invite's return value and the emitted link — only its hash is
12// ever persisted; see hashToken.
13func newToken() (string, error) {
14 b := make([]byte, 32)
15 if _, err := rand.Read(b); err != nil {
16 return "", err
17 }
18 return hex.EncodeToString(b), nil
19}
20
21// hashToken digests token with SHA-256, hex-encoded, lowercase. This
22// is the only form of the token idear ever writes to the database —
23// sessions already holds nothing but digests, and an addon must not
24// be laxer than the core it rides on.
25func hashToken(token string) string {
26 sum := sha256.Sum256([]byte(token))
27 return hex.EncodeToString(sum[:])
28}
29