mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
Add helper for decrypting via PGP in tests
This commit is contained in:
@@ -62,6 +62,35 @@ func getPubKeyFiles(t *testing.T) (string, []string, error) {
|
|||||||
return tempDir, pubFiles, nil
|
return tempDir, pubFiles, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testPGPDecrypt(tb testing.TB, privKey, enc string) string {
|
||||||
|
tb.Helper()
|
||||||
|
|
||||||
|
privKeyBytes, err := base64.StdEncoding.DecodeString(privKey)
|
||||||
|
if err != nil {
|
||||||
|
tb.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ptBuf := bytes.NewBuffer(nil)
|
||||||
|
entity, err := openpgp.ReadEntity(packet.NewReader(bytes.NewBuffer(privKeyBytes)))
|
||||||
|
if err != nil {
|
||||||
|
tb.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var rootBytes []byte
|
||||||
|
rootBytes, err = base64.StdEncoding.DecodeString(enc)
|
||||||
|
if err != nil {
|
||||||
|
tb.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
entityList := &openpgp.EntityList{entity}
|
||||||
|
md, err := openpgp.ReadMessage(bytes.NewBuffer(rootBytes), entityList, nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
tb.Fatal(err)
|
||||||
|
}
|
||||||
|
ptBuf.ReadFrom(md.UnverifiedBody)
|
||||||
|
return ptBuf.String()
|
||||||
|
}
|
||||||
|
|
||||||
func parseDecryptAndTestUnsealKeys(t *testing.T,
|
func parseDecryptAndTestUnsealKeys(t *testing.T,
|
||||||
input, rootToken string,
|
input, rootToken string,
|
||||||
fingerprints bool,
|
fingerprints bool,
|
||||||
|
|||||||
Reference in New Issue
Block a user