MCPcopy
hub / github.com/FiloSottile/age / TestDecryptNativeIdentitiesFirst

Function TestDecryptNativeIdentitiesFirst

age_test.go:336–368  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

334}
335
336func TestDecryptNativeIdentitiesFirst(t *testing.T) {
337 correct, err := age.GenerateX25519Identity()
338 if err != nil {
339 t.Fatal(err)
340 }
341 unrelated, err := age.GenerateX25519Identity()
342 if err != nil {
343 t.Fatal(err)
344 }
345
346 buf := &bytes.Buffer{}
347 w, err := age.Encrypt(buf, correct.Recipient())
348 if err != nil {
349 t.Fatal(err)
350 }
351 if err := w.Close(); err != nil {
352 t.Fatal(err)
353 }
354
355 nonNative := &testIdentity{}
356
357 // Pass identities: unrelated native, non-native, correct native.
358 // Native identities should be tried first, so correct should match
359 // before nonNative is ever called.
360 _, err = age.Decrypt(bytes.NewReader(buf.Bytes()), unrelated, nonNative, correct)
361 if err != nil {
362 t.Fatal(err)
363 }
364
365 if nonNative.called {
366 t.Error("non-native identity was called, but native identities should be tried first")
367 }
368}
369
370type stanzaTypeRecipient string
371

Callers

nothing calls this directly

Calls 7

GenerateX25519IdentityFunction · 0.92
EncryptFunction · 0.92
DecryptFunction · 0.92
BytesMethod · 0.80
RecipientMethod · 0.45
CloseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…