本文整理匯總了Golang中camlistore/org/third_party/code/google/com/p/go/crypto/openpgp.ReadKeyRing函數的典型用法代碼示例。如果您正苦於以下問題:Golang ReadKeyRing函數的具體用法?Golang ReadKeyRing怎麽用?Golang ReadKeyRing使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ReadKeyRing函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FetchEntity
func (fe *FileEntityFetcher) FetchEntity(keyId string) (*openpgp.Entity, error) {
f, err := wkfs.Open(fe.File)
if err != nil {
return nil, fmt.Errorf("jsonsign: FetchEntity: %v", err)
}
defer f.Close()
el, err := openpgp.ReadKeyRing(f)
if err != nil {
return nil, fmt.Errorf("jsonsign: openpgp.ReadKeyRing of %q: %v", fe.File, err)
}
for _, e := range el {
pubk := &e.PrivateKey.PublicKey
if pubk.KeyIdString() != keyId {
continue
}
if e.PrivateKey.Encrypted {
if err := fe.decryptEntity(e); err == nil {
return e, nil
} else {
return nil, err
}
}
return e, nil
}
return nil, fmt.Errorf("jsonsign: entity for keyid %q not found in %q", keyId, fe.File)
}
示例2: KeyIdFromRing
// KeyIdFromRing returns the public keyId contained in the secret
// ring file secRing. It expects only one keyId in this secret ring
// and returns an error otherwise.
func KeyIdFromRing(secRing string) (keyId string, err error) {
f, err := os.Open(secRing)
if err != nil {
return "", fmt.Errorf("Could not open secret ring file %v: %v", secRing, err)
}
defer f.Close()
el, err := openpgp.ReadKeyRing(f)
if err != nil {
return "", fmt.Errorf("Could not read secret ring file %s: %v", secRing, err)
}
if len(el) != 1 {
return "", fmt.Errorf("Secret ring file %v contained %d identities; expected 1", secRing, len(el))
}
ent := el[0]
return ent.PrimaryKey.KeyIdShortString(), nil
}
示例3: keyIdFromRing
func keyIdFromRing(filename string) (keyId string, err error) {
f, err := os.Open(filename)
if err != nil {
return "", fmt.Errorf("reading identity secret ring file: %v", err)
}
defer f.Close()
el, err := openpgp.ReadKeyRing(f)
if err != nil {
return "", fmt.Errorf("reading identity secret ring file %s: %v", filename, err)
}
if len(el) != 1 {
return "", fmt.Errorf("identity secret ring file contained %d identities; expected 1", len(el))
}
ent := el[0]
return ent.PrimaryKey.KeyIdShortString(), nil
}
示例4: EntityFromSecring
// EntityFromSecring returns the openpgp Entity from keyFile that matches keyId.
// If empty, keyFile defaults to osutil.SecretRingFile().
func EntityFromSecring(keyId, keyFile string) (*openpgp.Entity, error) {
if keyId == "" {
return nil, errors.New("empty keyId passed to EntityFromSecring")
}
keyId = strings.ToUpper(keyId)
if keyFile == "" {
keyFile = osutil.SecretRingFile()
}
secring, err := wkfs.Open(keyFile)
if err != nil {
return nil, fmt.Errorf("jsonsign: failed to open keyring: %v", err)
}
defer secring.Close()
el, err := openpgp.ReadKeyRing(secring)
if err != nil {
return nil, fmt.Errorf("openpgp.ReadKeyRing of %q: %v", keyFile, err)
}
var entity *openpgp.Entity
for _, e := range el {
pk := e.PrivateKey
if pk == nil || (pk.KeyIdString() != keyId && pk.KeyIdShortString() != keyId) {
continue
}
entity = e
}
if entity == nil {
found := []string{}
for _, e := range el {
pk := e.PrivateKey
if pk == nil {
continue
}
found = append(found, pk.KeyIdShortString())
}
return nil, fmt.Errorf("didn't find a key in %q for keyId %q; other keyIds in file = %v", keyFile, keyId, found)
}
return entity, nil
}
示例5: TestWriteKeyRing
func TestWriteKeyRing(t *testing.T) {
ent, err := EntityFromSecring("26F5ABDA", "testdata/test-secring.gpg")
if err != nil {
t.Fatalf("NewEntity: %v", err)
}
var buf bytes.Buffer
err = WriteKeyRing(&buf, openpgp.EntityList([]*openpgp.Entity{ent}))
if err != nil {
t.Fatalf("WriteKeyRing: %v", err)
}
el, err := openpgp.ReadKeyRing(&buf)
if err != nil {
t.Fatalf("ReadKeyRing: %v", err)
}
if len(el) != 1 {
t.Fatalf("ReadKeyRing read %d entities; want 1", len(el))
}
orig := entityString(ent)
got := entityString(el[0])
if orig != got {
t.Fatalf("original vs. wrote-then-read entities differ:\norig: %s\n got: %s", orig, got)
}
}