當前位置: 首頁>>代碼示例>>Golang>>正文


Golang armor.Decode函數代碼示例

本文整理匯總了Golang中code/google/com/p/go/crypto/openpgp/armor.Decode函數的典型用法代碼示例。如果您正苦於以下問題:Golang Decode函數的具體用法?Golang Decode怎麽用?Golang Decode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Decode函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: testReadDigestDups

func testReadDigestDups(t *testing.T, testfile string) {
	f := MustInput(t, "rtt-140.asc")
	defer f.Close()
	block, err := armor.Decode(f)
	if err != nil {
		t.Fatal(err)
	}
	var opkr *OpaqueKeyring
	for kr := range ReadOpaqueKeyrings(block.Body) {
		if opkr != nil {
			t.Fatal("unexpected keyring")
		}
		opkr = kr
	}
	assert.Equal(t, len(opkr.Packets), 24)

	pubkey, err := opkr.Parse()
	assert.Nil(t, err)
	var buf bytes.Buffer
	err = WritePackets(&buf, pubkey)
	assert.Nil(t, err)
	opkr = nil
	for kr := range ReadOpaqueKeyrings(bytes.NewBuffer(buf.Bytes())) {
		if opkr != nil {
			t.Fatal("unexpected keyring")
		}
		opkr = kr
	}
	assert.Equal(t, len(opkr.Packets), 24)
}
開發者ID:cmars,項目名稱:hockeypuck,代碼行數:30,代碼來源:worker_test.go

示例2: v3KeyReader

func v3KeyReader(t *testing.T) io.Reader {
	armorBlock, err := armor.Decode(bytes.NewBufferString(keySigV3Armor))
	if err != nil {
		t.Fatalf("armor Decode failed: %v", err)
	}
	return armorBlock.Body
}
開發者ID:tomzhang,項目名稱:golang-devops-stuff,代碼行數:7,代碼來源:signature_v3_test.go

示例3: Add

// Add responds to /pks/add HKP requests.
func (w *Worker) Add(a *hkp.Add) {
	// Parse armored keytext
	var changes []*KeyChange
	var readErrors []*ReadKeyResult
	// Check and decode the armor
	armorBlock, err := armor.Decode(bytes.NewBufferString(a.Keytext))
	if err != nil {
		a.Response() <- &ErrorResponse{err}
		return
	}
	for readKey := range ReadKeys(armorBlock.Body) {
		if readKey.Error != nil {
			readErrors = append(readErrors, readKey)
		} else {
			change := w.UpsertKey(readKey.Pubkey)
			if change.Error != nil {
				log.Printf("Error updating key [%s]: %v\n", readKey.Pubkey.Fingerprint(),
					change.Error)
			} else {
				go w.notifyChange(change)
			}
			changes = append(changes, change)
		}
	}
	a.Response() <- &AddResponse{Changes: changes, Errors: readErrors}
}
開發者ID:kisom,項目名稱:hockeypuck,代碼行數:27,代碼來源:add.go

示例4: VerifySignature

func (vr *VerifyRequest) VerifySignature() bool {
	armorData := reArmor(vr.CamliSig)
	block, _ := armor.Decode(bytes.NewBufferString(armorData))
	if block == nil {
		return vr.fail("can't parse camliSig armor")
	}
	var p packet.Packet
	var err error
	p, err = packet.Read(block.Body)
	if err != nil {
		return vr.fail("error reading PGP packet from camliSig: " + err.Error())
	}
	sig, ok := p.(*packet.Signature)
	if !ok {
		return vr.fail("PGP packet isn't a signature packet")
	}
	if sig.Hash != crypto.SHA1 && sig.Hash != crypto.SHA256 {
		return vr.fail("I can only verify SHA1 or SHA256 signatures")
	}
	if sig.SigType != packet.SigTypeBinary {
		return vr.fail("I can only verify binary signatures")
	}
	hash := sig.Hash.New()
	hash.Write(vr.bp) // payload bytes
	err = vr.PublicKeyPacket.VerifySignature(hash, sig)
	if err != nil {
		return vr.fail(fmt.Sprintf("bad signature: %s", err))
	}
	vr.SignerKeyId = vr.PublicKeyPacket.KeyIdString()
	return true
}
開發者ID:pombredanne,項目名稱:camlistore,代碼行數:31,代碼來源:verify.go

示例5: Verify

// Verify() checks the validity of a signature for some data,
// and returns a boolean set to true if valid and an OpenPGP Entity
func Verify(data string, signature string, keyring io.Reader) (valid bool, entity *openpgp.Entity, err error) {
	valid = false

	// re-armor signature and transform into io.Reader
	sigReader := strings.NewReader(reArmor(signature))

	// decode armor
	sigBlock, err := armor.Decode(sigReader)
	if err != nil {
		panic(err)
	}
	if sigBlock.Type != "PGP SIGNATURE" {
		err = fmt.Errorf("Wrong signature type '%s'", sigBlock.Type)
		panic(err)
	}

	// convert to io.Reader
	srcReader := strings.NewReader(data)

	// open the keyring
	ring, err := openpgp.ReadKeyRing(keyring)
	if err != nil {
		panic(err)
	}

	entity, err = openpgp.CheckDetachedSignature(ring, srcReader, sigBlock.Body)
	if err != nil {
		panic(err)
	}

	// we passed, signature is valid
	valid = true

	return
}
開發者ID:jeffbryner,項目名稱:mig,代碼行數:37,代碼來源:verify.go

示例6: TestReadKey0ff16c87

func TestReadKey0ff16c87(t *testing.T) {
	f := MustInput(t, "0ff16c87.asc")
	block, err := armor.Decode(f)
	if err != nil {
		t.Fatal(err)
	}
	var key *Pubkey
	for keyRead := range ReadKeys(block.Body) {
		key = keyRead.Pubkey
	}
	assert.NotNil(t, key)
	key.Visit(func(rec PacketRecord) error {
		_, err = rec.GetOpaquePacket()
		switch r := rec.(type) {
		case *Pubkey:
			assert.NotEmpty(t, r.Packet)
		case *Subkey:
			assert.NotEmpty(t, r.Packet)
		case *Signature:
			assert.NotEmpty(t, r.Packet)
		case *UserId:
			assert.NotEmpty(t, r.Packet)
		case *UserAttribute:
			assert.NotEmpty(t, r.Packet)
		}
		assert.Nil(t, err)
		return nil
	})
}
開發者ID:pruthvirajsinh,項目名稱:prlpks,代碼行數:29,代碼來源:io_test.go

示例7: ReadEntity

func ReadEntity(privKeyArmor string) (*openpgp.Entity, error) {
	block, err := armor.Decode(strings.NewReader(privKeyArmor))
	if err != nil {
		return nil, err
	}
	return openpgp.ReadEntity(packet.NewReader(block.Body))
}
開發者ID:Braintreep,項目名稱:scramble,代碼行數:7,代碼來源:crypto.go

示例8: main

func main() {
	sigReader := strings.NewReader(sig)
	sigBlock, err := armor.Decode(sigReader)
	if err != nil {
		panic(err)
	}
	if sigBlock.Type != openpgp.SignatureType {
		panic("not a signature type")
	}

	dataReader := strings.NewReader(data)

	krfd, err := os.Open("/home/ulfr/.gnupg/pubring.gpg")
	if err != nil {
		panic(err)
	}
	defer krfd.Close()

	keyring, err := openpgp.ReadKeyRing(krfd)
	if err != nil {
		panic(err)
	}
	entity, err := openpgp.CheckDetachedSignature(
		keyring, dataReader, sigBlock.Body)
	if err != nil {
		panic(err)
	}
	fmt.Printf("valid signature from key %s\n",
		hex.EncodeToString(entity.PrimaryKey.Fingerprint[:]))
}
開發者ID:jvehent,項目名稱:go-toybox,代碼行數:30,代碼來源:verifsig.go

示例9: extractEncryptedBodyMime

func extractEncryptedBodyMime(m *Message) (io.Reader, error) {
	ps := m.mpContent.parts
	if len(ps) != 2 {
		return nil, fmt.Errorf("failed to extract encrypted body, expecting 2 mime parts, got %d", len(ps))
	}
	block, err := armor.Decode(strings.NewReader(ps[1].Body))
	if err != nil {
		return nil, errors.New("armor decode of encrypted body failed: " + err.Error())
	}
	return block.Body, nil
}
開發者ID:nymsio,項目名稱:pgpmail,代碼行數:11,代碼來源:decrypt.go

示例10: readArmored

// readArmored reads an armored block with the given type.
func readArmored(r io.Reader, expectedType string) (body io.Reader, err error) {
	block, err := armor.Decode(r)
	if err != nil {
		return
	}

	if block.Type != expectedType {
		return nil, errors.InvalidArgumentError("expected '" + expectedType + "', got: " + block.Type)
	}

	return block.Body, nil
}
開發者ID:Bobberino,項目名稱:musings,代碼行數:13,代碼來源:read.go

示例11: Decrypt

// Decrypt tries to decrypt an OpenPGP armored block using the provided decryption keys
// and passphrase. If succesfull the plain content of the block is returned as []byte.
func Decrypt(d []byte, decryptionKeys *openpgp.EntityList, passphrase string) ([]byte, error) {
	var armoredBlock *armor.Block
	var message *openpgp.MessageDetails
	var plain []byte
	var err error

	if d == nil {
		return nil, nil
	}

	// Decode the OpenPGP armored block
	armoredBlock, err = armor.Decode(bytes.NewReader(d))
	if err != nil {
		return nil, err
	}

	// Extract the message from the OpenPGP armored block
	message, err = openpgp.ReadMessage(armoredBlock.Body, decryptionKeys,
		func(keys []openpgp.Key, symmetric bool) ([]byte, error) {
			kp := []byte(passphrase)

			if symmetric {
				return kp, nil
			}

			for _, k := range keys {
				err := k.PrivateKey.Decrypt(kp)
				if err == nil {
					// If no error were returned, we could succesfully
					// decrypt the message using the provided private key
					return nil, nil
				}
			}

			return nil, fmt.Errorf("Unable to decrypt trousseau data store. " +
				"Invalid passphrase supplied.")
		},
		nil)
	if err != nil {
		return nil, fmt.Errorf("unable to decrypt trousseau data store. " +
			"No private key able to decrypt it found in your keyring.")
	}

	// Read the plain message bytes
	plain, err = ioutil.ReadAll(message.UnverifiedBody)
	if err != nil {
		return nil, err
	}

	return plain, err
}
開發者ID:temal-,項目名稱:trousseau,代碼行數:53,代碼來源:actions.go

示例12: ReadArmoredKeyRing

// ReadArmoredKeyRing reads one or more public/private keys from an armor keyring file.
func ReadArmoredKeyRing(r io.Reader) (EntityList, error) {
	block, err := armor.Decode(r)
	if err == io.EOF {
		return nil, errors.InvalidArgumentError("no armored data found")
	}
	if err != nil {
		return nil, err
	}
	if block.Type != PublicKeyType && block.Type != PrivateKeyType {
		return nil, errors.InvalidArgumentError("expected public or private key block, got: " + block.Type)
	}

	return ReadKeyRing(block.Body)
}
開發者ID:rajasaur,項目名稱:sync_gateway,代碼行數:15,代碼來源:keys.go

示例13: MustInputAscKeys

func MustInputAscKeys(t *testing.T, name string) (result []*Pubkey) {
	f := MustInput(t, name)
	defer f.Close()
	block, err := armor.Decode(f)
	if err != nil {
		t.Fatal(err)
	}
	for keyRead := range ReadKeys(block.Body) {
		if keyRead.Error != nil {
			t.Fatal(keyRead.Error)
		}
		result = append(result, keyRead.Pubkey)
	}
	return
}
開發者ID:cmars,項目名稱:hockeypuck,代碼行數:15,代碼來源:util_test.go

示例14: extractInlineBody

func extractInlineBody(body string) (io.Reader, error) {
	start := strings.Index(body, beginPgpMessage)
	if start == -1 {
		return nil, nil
	}

	end := strings.Index(body, endPgpMessage)
	if end == -1 {
		return nil, errors.New("End of inline PGP message not found")
	}
	armored := body[start:(end + len(endPgpMessage))]
	block, err := armor.Decode(bytes.NewReader([]byte(armored)))
	if err != nil {
		return nil, errors.New("armor decode of encrypted body failed: " + err.Error())
	}
	return block.Body, nil
}
開發者ID:nymsio,項目名稱:pgpmail,代碼行數:17,代碼來源:decrypt.go

示例15: TestValidateKey

func TestValidateKey(t *testing.T) {
	f := MustInput(t, "tails.asc")
	defer f.Close()
	block, err := armor.Decode(f)
	if err != nil {
		t.Fatal(err)
	}
	var keys []*Pubkey
	for keyRead := range ReadKeys(block.Body) {
		keys = append(keys, keyRead.Pubkey)
	}
	assert.Equal(t, 1, len(keys))
	assert.Equal(t, 2, len(keys[0].userIds))
	for i := 0; i < 2; i++ {
		assert.NotEmpty(t, keys[0].userIds[i].ScopedDigest)
	}
}
開發者ID:pruthvirajsinh,項目名稱:prlpks,代碼行數:17,代碼來源:worker_test.go


注:本文中的code/google/com/p/go/crypto/openpgp/armor.Decode函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。