func decodeCaveatV2V3(version Version, key *KeyPair, caveat []byte) (*ThirdPartyCaveatInfo, error) {
	origCaveat := caveat
	if len(caveat) < 1+publicKeyPrefixLen+KeyLen+NonceLen+box.Overhead {
		return nil, errgo.New("caveat id too short")
	}
	caveat = caveat[1:] // skip version (already checked)

	publicKeyPrefix, caveat := caveat[:publicKeyPrefixLen], caveat[publicKeyPrefixLen:]
	if !bytes.Equal(key.Public.Key[:publicKeyPrefixLen], publicKeyPrefix) {
		return nil, errgo.New("public key mismatch")
	}

	var firstPartyPub PublicKey
	copy(firstPartyPub.Key[:], caveat[:KeyLen])
	caveat = caveat[KeyLen:]

	var nonce [NonceLen]byte
	copy(nonce[:], caveat[:NonceLen])
	caveat = caveat[NonceLen:]

	data, ok := box.Open(nil, caveat, &nonce, firstPartyPub.boxKey(), key.Private.boxKey())
	if !ok {
		return nil, errgo.Newf("cannot decrypt caveat id")
	}
	rootKey, ns, condition, err := decodeSecretPartV2V3(version, data)
	if err != nil {
		return nil, errgo.Notef(err, "invalid secret part")
	}
	return &ThirdPartyCaveatInfo{
		Condition:           condition,
		FirstPartyPublicKey: firstPartyPub,
		ThirdPartyKeyPair:   *key,
		RootKey:             rootKey,
		Caveat:              origCaveat,
		Version:             version,
		Namespace:           ns,
	}, nil
}
// decodeCaveatV2V3 decodes a version 2 or version 3 caveat.
decodeCaveatV2V3 decodes a version 2 or version 3 caveat.
// decodeCaveatV2V3 decodes a version 2 or version 3 caveat .
func decodeCaveatV2V3(version Version, key *KeyPair, caveat []byte) (*ThirdPartyCaveatInfo, error) {
	origCaveat := caveat
	if len(caveat) < 1+publicKeyPrefixLen+KeyLen+NonceLen+box.Overhead {
		return nil, errgo.New("caveat id too short")
	}
	caveat = caveat[1:] 
	publicKeyPrefix, caveat := caveat[:publicKeyPrefixLen], caveat[publicKeyPrefixLen:]
	if !bytes.Equal(key.Public.Key[:publicKeyPrefixLen], publicKeyPrefix) {
		return nil, errgo.New("public key mismatch")
	}
	var firstPartyPub PublicKey
	copy(firstPartyPub.Key[:], caveat[:KeyLen])
	caveat = caveat[KeyLen:]
	var nonce [NonceLen]byte
	copy(nonce[:], caveat[:NonceLen])
	caveat = caveat[NonceLen:]
	data, ok := box.Open(nil, caveat, &nonce, firstPartyPub.boxKey(), key.Private.boxKey())
	if !ok {
		return nil, errgo.Newf("cannot decrypt caveat id")
	}
	rootKey, ns, condition, err := decodeSecretPartV2V3(version, data)
	if err != nil {
		return nil, errgo.Notef(err, "invalid secret part")
	}
	return &ThirdPartyCaveatInfo{
		Condition:           condition,
		FirstPartyPublicKey: firstPartyPub,
		ThirdPartyKeyPair:   *key,
		RootKey:             rootKey,
		Caveat:              origCaveat,
		Version:             version,
		Namespace:           ns,
	}, nil
}
func decodeCaveatV2V3 ( version Version , key * KeyPair , caveat [ ] byte ) ( * ThirdPartyCaveatInfo , error ) { origCaveat := caveat if len ( caveat ) < 1 + publicKeyPrefixLen + KeyLen + NonceLen + box . Overhead { return nil , errgo . New ( " " ) } caveat = caveat [ 1 : ] publicKeyPrefix , caveat := caveat [ : publicKeyPrefixLen ] , caveat [ publicKeyPrefixLen : ] if ! bytes . Equal ( key . Public . Key [ : publicKeyPrefixLen ] , publicKeyPrefix ) { return nil , errgo . New ( " " ) } var firstPartyPub PublicKey copy ( firstPartyPub . Key [ : ] , caveat [ : KeyLen ] ) caveat = caveat [ KeyLen : ] var nonce [ NonceLen ] byte copy ( nonce [ : ] , caveat [ : NonceLen ] ) caveat = caveat [ NonceLen : ] data , ok := box . Open ( nil , caveat , & nonce , firstPartyPub . boxKey ( ) , key . Private . boxKey ( ) ) if ! ok { return nil , errgo . Newf ( " " ) } rootKey , ns , condition , err := decodeSecretPartV2V3 ( version , data ) if err != nil { return nil , errgo . Notef ( err , " " ) } return & ThirdPartyCaveatInfo { Condition : condition , FirstPartyPublicKey : firstPartyPub , ThirdPartyKeyPair : * key , RootKey : rootKey , Caveat : origCaveat , Version : version , Namespace : ns , } , nil }
decodeCaveatV2V3 decodes a version 2 or version 3 caveat.
decodeCaveatV2V3 decodes a version 2 or version 3 caveat .
// skip version (already checked)