(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func 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 | |
| 39 | func TestCryptBadDecrypt(t *testing.T) { |
| 40 | prefix := "__gj:enc:" |
nothing calls this directly
no test coverage detected