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

Function TestLabels

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

Source from the content-addressed store, hash-verified

272}
273
274func TestLabels(t *testing.T) {
275 scrypt, err := age.NewScryptRecipient("xxx")
276 if err != nil {
277 t.Fatal(err)
278 }
279 i, err := age.GenerateX25519Identity()
280 if err != nil {
281 t.Fatal(err)
282 }
283 x25519 := i.Recipient()
284 pqc := testRecipient{[]string{"postquantum"}}
285 pqcAndFoo := testRecipient{[]string{"postquantum", "foo"}}
286 fooAndPQC := testRecipient{[]string{"foo", "postquantum"}}
287
288 if _, err := age.Encrypt(io.Discard, scrypt, scrypt); err == nil {
289 t.Error("expected two scrypt recipients to fail")
290 }
291 if _, err := age.Encrypt(io.Discard, scrypt, x25519); err == nil {
292 t.Error("expected x25519 mixed with scrypt to fail")
293 }
294 if _, err := age.Encrypt(io.Discard, x25519, scrypt); err == nil {
295 t.Error("expected x25519 mixed with scrypt to fail")
296 }
297 if _, err := age.Encrypt(io.Discard, pqc, x25519); err == nil {
298 t.Error("expected x25519 mixed with pqc to fail")
299 }
300 if _, err := age.Encrypt(io.Discard, x25519, pqc); err == nil {
301 t.Error("expected x25519 mixed with pqc to fail")
302 }
303 if _, err := age.Encrypt(io.Discard, pqc, pqc); err != nil {
304 t.Errorf("expected two pqc to work, got %v", err)
305 }
306 if _, err := age.Encrypt(io.Discard, pqc); err != nil {
307 t.Errorf("expected one pqc to work, got %v", err)
308 }
309 if _, err := age.Encrypt(io.Discard, pqcAndFoo, pqc); err == nil {
310 t.Error("expected pqc+foo mixed with pqc to fail")
311 }
312 if _, err := age.Encrypt(io.Discard, pqc, pqcAndFoo); err == nil {
313 t.Error("expected pqc+foo mixed with pqc to fail")
314 }
315 if _, err := age.Encrypt(io.Discard, pqc, pqc, pqcAndFoo); err == nil {
316 t.Error("expected pqc+foo mixed with pqc to fail")
317 }
318 if _, err := age.Encrypt(io.Discard, pqcAndFoo, pqcAndFoo); err != nil {
319 t.Errorf("expected two pqc+foo to work, got %v", err)
320 }
321 if _, err := age.Encrypt(io.Discard, pqcAndFoo, fooAndPQC); err != nil {
322 t.Errorf("expected pqc+foo mixed with foo+pqc to work, got %v", err)
323 }
324}
325
326// testIdentity is a non-native identity that records if Unwrap is called.
327type testIdentity struct {

Callers

nothing calls this directly

Calls 5

NewScryptRecipientFunction · 0.92
GenerateX25519IdentityFunction · 0.92
EncryptFunction · 0.92
RecipientMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…