github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/libkb/pgp_dec_test.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package libkb
     5  
     6  import (
     7  	"strings"
     8  	"testing"
     9  )
    10  
    11  func TestPGPDecryptBasic(t *testing.T) {
    12  	tc := SetupTest(t, "pgp_encrypt", 1)
    13  	defer tc.Cleanup()
    14  	keyA, err := tc.MakePGPKey("keya@keybase.io")
    15  	if err != nil {
    16  		t.Fatal(err)
    17  	}
    18  	keyB, err := tc.MakePGPKey("keyb@keybase.io")
    19  	if err != nil {
    20  		t.Fatal(err)
    21  	}
    22  
    23  	mid := NewBufferCloser()
    24  	msg := "Is it time for lunch?"
    25  	recipients := []*PGPKeyBundle{keyA, keyB}
    26  	if err := PGPEncrypt(strings.NewReader(msg), mid, nil, recipients); err != nil {
    27  		t.Fatal(err)
    28  	}
    29  
    30  	out := NewBufferCloser()
    31  	if _, err := PGPDecryptWithBundles(tc.G, mid, out, recipients); err != nil {
    32  		t.Fatal(err)
    33  	}
    34  
    35  	dec := out.String()
    36  	if dec != msg {
    37  		t.Errorf("decoded: %q, expected %q", dec, msg)
    38  	}
    39  }