Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
5245b27e
Commit
5245b27e
authored
Mar 15, 2011
by
Brad Fitzpatrick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
openpgp: add PublicKey KeyId string accessors
R=agl, agl1 CC=golang-dev
https://golang.org/cl/4297041
parent
a5697251
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
2 deletions
+23
-2
public_key.go
src/pkg/crypto/openpgp/packet/public_key.go
+13
-0
public_key_test.go
src/pkg/crypto/openpgp/packet/public_key_test.go
+10
-2
No files found.
src/pkg/crypto/openpgp/packet/public_key.go
View file @
5245b27e
...
...
@@ -11,6 +11,7 @@ import (
"crypto/rsa"
"crypto/sha1"
"encoding/binary"
"fmt"
"hash"
"io"
"os"
...
...
@@ -239,6 +240,18 @@ func (pk *PublicKey) VerifyUserIdSignature(id string, sig *Signature) (err os.Er
return
pk
.
VerifySignature
(
h
,
sig
)
}
// KeyIdString returns the public key's fingerprint in capital hex
// (e.g. "6C7EE1B8621CC013").
func
(
pk
*
PublicKey
)
KeyIdString
()
string
{
return
fmt
.
Sprintf
(
"%X"
,
pk
.
Fingerprint
[
12
:
20
])
}
// KeyIdShortString returns the short form of public key's fingerprint
// in capital hex, as shown by gpg --list-keys (e.g. "621CC013").
func
(
pk
*
PublicKey
)
KeyIdShortString
()
string
{
return
fmt
.
Sprintf
(
"%X"
,
pk
.
Fingerprint
[
16
:
20
])
}
// A parsedMPI is used to store the contents of a big integer, along with the
// bit length that was specified in the original input. This allows the MPI to
// be reserialized exactly.
...
...
src/pkg/crypto/openpgp/packet/public_key_test.go
View file @
5245b27e
...
...
@@ -16,9 +16,11 @@ var pubKeyTests = []struct {
creationTime
uint32
pubKeyAlgo
PublicKeyAlgorithm
keyId
uint64
keyIdString
string
keyIdShort
string
}{
{
rsaPkDataHex
,
rsaFingerprintHex
,
0x4d3c5c10
,
PubKeyAlgoRSA
,
0xa34d7e18c20c31bb
},
{
dsaPkDataHex
,
dsaFingerprintHex
,
0x4d432f89
,
PubKeyAlgoDSA
,
0x8e8fbe54062f19ed
},
{
rsaPkDataHex
,
rsaFingerprintHex
,
0x4d3c5c10
,
PubKeyAlgoRSA
,
0xa34d7e18c20c31bb
,
"A34D7E18C20C31BB"
,
"C20C31BB"
},
{
dsaPkDataHex
,
dsaFingerprintHex
,
0x4d432f89
,
PubKeyAlgoDSA
,
0x8e8fbe54062f19ed
,
"8E8FBE54062F19ED"
,
"062F19ED"
},
}
func
TestPublicKeyRead
(
t
*
testing
.
T
)
{
...
...
@@ -46,6 +48,12 @@ func TestPublicKeyRead(t *testing.T) {
if
pk
.
KeyId
!=
test
.
keyId
{
t
.
Errorf
(
"#%d: bad keyid got:%x want:%x"
,
i
,
pk
.
KeyId
,
test
.
keyId
)
}
if
g
,
e
:=
pk
.
KeyIdString
(),
test
.
keyIdString
;
g
!=
e
{
t
.
Errorf
(
"#%d: bad KeyIdString got:%q want:%q"
,
i
,
g
,
e
)
}
if
g
,
e
:=
pk
.
KeyIdShortString
(),
test
.
keyIdShort
;
g
!=
e
{
t
.
Errorf
(
"#%d: bad KeyIdShortString got:%q want:%q"
,
i
,
g
,
e
)
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment