File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed
Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
55and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) .
66
7+ ## Unreleased
8+ ### Added
9+ - API to ASCII encode (armor) KeyRings:
10+ ```go
11+ func (keyRing *KeyRing) Armor() (string, error)
12+ ```
13+
714## [ 3.1.0] 2024-11-25
815### Added
916- Add decryption option to allow disabling the integrity tag requirement.
Original file line number Diff line number Diff line change 77
88 "github.com/ProtonMail/go-crypto/openpgp/packet"
99 openpgp "github.com/ProtonMail/go-crypto/openpgp/v2"
10+ "github.com/ProtonMail/gopenpgp/v2/armor"
11+ "github.com/ProtonMail/gopenpgp/v2/constants"
1012 "github.com/pkg/errors"
1113)
1214
@@ -133,6 +135,16 @@ func (keyRing *KeyRing) Serialize() ([]byte, error) {
133135 return buffer .Bytes (), nil
134136}
135137
138+ // Armor returns the armored keyring as a string with default gopenpgp headers.
139+ func (keyRing * KeyRing ) Armor () (string , error ) {
140+ serialized , err := keyRing .Serialize ()
141+ if err != nil {
142+ return "" , err
143+ }
144+
145+ return armor .ArmorWithType (serialized , constants .PublicKeyHeader )
146+ }
147+
136148// --- Extract info from key
137149
138150// CountEntities returns the number of entities in the keyring.
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package crypto
22
33import (
44 "crypto/rsa"
5+ "regexp"
56 "testing"
67
78 "github.com/stretchr/testify/assert"
@@ -160,6 +161,14 @@ func TestSerializeParse(t *testing.T) {
160161 }
161162}
162163
164+ func TestArmor (t * testing.T ) {
165+ armoredRing , err := keyRingTestMultiple .Armor ()
166+ assert .Nil (t , err )
167+
168+ rTest := regexp .MustCompile (`(?s)^-----BEGIN PGP PUBLIC KEY BLOCK-----.*Version: GopenPGP [0-9]+\.[0-9]+\.[0-9]+.*-----END PGP PUBLIC KEY BLOCK-----$` )
169+ assert .Regexp (t , rTest , armoredRing )
170+ }
171+
163172func TestClearPrivateKey (t * testing.T ) {
164173 keyRingCopy , err := keyRingTestMultiple .Copy ()
165174 if err != nil {
You can’t perform that action at this time.
0 commit comments