(t *testing.T)
| 135 | } |
| 136 | |
| 137 | func TestEncryptDecryptRoundTrip(t *testing.T) { |
| 138 | // Generate a real key pair for testing |
| 139 | pub, priv, err := box.GenerateKey(rand.Reader) |
| 140 | if err != nil { |
| 141 | t.Fatalf("failed to generate key pair: %v", err) |
| 142 | } |
| 143 | |
| 144 | // Encode public key as base64 |
| 145 | pubB64 := base64.StdEncoding.EncodeToString(pub[:]) |
| 146 | plaintext := "test-secret-value" |
| 147 | |
| 148 | // Encrypt using our function |
| 149 | encrypted, err := encryptWithPublicKey(pubB64, plaintext) |
| 150 | if err != nil { |
| 151 | t.Fatalf("encryptWithPublicKey() error = %v", err) |
| 152 | } |
| 153 | |
| 154 | // Decrypt using NaCl box to verify correctness |
| 155 | cipherBytes, err := base64.StdEncoding.DecodeString(encrypted) |
| 156 | if err != nil { |
| 157 | t.Fatalf("failed to decode encrypted data: %v", err) |
| 158 | } |
| 159 | |
| 160 | decrypted, ok := box.OpenAnonymous(nil, cipherBytes, pub, priv) |
| 161 | if !ok { |
| 162 | t.Fatal("decryption failed - ciphertext was not valid") |
| 163 | } |
| 164 | |
| 165 | if string(decrypted) != plaintext { |
| 166 | t.Errorf("decrypted = %q, want %q", string(decrypted), plaintext) |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | func TestSecretSetClientOptions(t *testing.T) { |
| 171 | t.Run("defaults include timeout", func(t *testing.T) { |
nothing calls this directly
no test coverage detected