MCPcopy Index your code
hub / github.com/dosco/graphjin / TestCryptEncryptDecrypt

Function TestCryptEncryptDecrypt

core/crypt_test.go:13–37  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestCryptEncryptDecrypt(t *testing.T) {
14 encPrefix := "__gj:foobar:"
15 decPrefix := "__gj:enc:"
16
17 js := []byte(fmt.Sprintf(
18 `{ me: "null", posts_cursor: "%s12345" }`, encPrefix))
19
20 expjs := []byte(
21 `{ me: "null", posts_cursor: "12345" }`)
22
23 key := [32]byte{}
24 _, err := io.ReadFull(rand.Reader, key[:])
25 assert.NoErrorFatal(t, err)
26
27 nonce := sha256.Sum256(js)
28
29 out1, err := encryptValues(
30 js, []byte(encPrefix), []byte(decPrefix), nonce[:], key)
31 assert.NoErrorFatal(t, err)
32
33 out2, err := decryptValues(out1, []byte(decPrefix), key)
34 assert.NoErrorFatal(t, err)
35
36 assert.Equals(t, expjs, out2)
37}
38
39func TestCryptBadDecrypt(t *testing.T) {
40 prefix := "__gj:enc:"

Callers

nothing calls this directly

Calls 2

encryptValuesFunction · 0.85
decryptValuesFunction · 0.85

Tested by

no test coverage detected