func encodeCaveatV1(
	condition string,
	rootKey []byte,
	thirdPartyPubKey *PublicKey,
	key *KeyPair,
) ([]byte, error) {
	var nonce [NonceLen]byte
	if _, err := rand.Read(nonce[:]); err != nil {
		return nil, errgo.Notef(err, "cannot generate random number for nonce")
	}
	plain := caveatRecord{
		RootKey:   rootKey,
		Condition: condition,
	}
	plainData, err := json.Marshal(&plain)
	if err != nil {
		return nil, errgo.Notef(err, "cannot marshal %#v", &plain)
	}
	sealed := box.Seal(nil, plainData, &nonce, thirdPartyPubKey.boxKey(), key.Private.boxKey())
	id := caveatJSON{
		ThirdPartyPublicKey: thirdPartyPubKey,
		FirstPartyPublicKey: &key.Public,
		Nonce:               nonce[:],
		Id:                  base64.StdEncoding.EncodeToString(sealed),
	}
	data, err := json.Marshal(id)
	if err != nil {
		return nil, errgo.Notef(err, "cannot marshal %#v", id)
	}
	buf := make([]byte, base64.StdEncoding.EncodedLen(len(data)))
	base64.StdEncoding.Encode(buf, data)
	return buf, nil
}
// encodeCaveatV1 creates a JSON-encoded third-party caveat
// with the given condtion and root key. The thirdPartyPubKey key
// represents the public key of the third party we're encrypting
// the caveat for; the key is the public/private key pair of the party
// that's adding the caveat.
encodeCaveatV1 creates a JSON-encoded third-party caveat
with the given condtion and root key. The thirdPartyPubKey key
represents the public key of the third party we're encrypting
the caveat for; the key is the public/private key pair of the party
that's adding the caveat.
// encodeCaveatV1 creates a JSON - encoded third - party caveat // with the given condtion and root key . The thirdPartyPubKey key // represents the public key of the third party we ' re encrypting // the caveat for ; the key is the public / private key pair of the party // that ' s adding the caveat .
func encodeCaveatV1(
	condition string,
	rootKey []byte,
	thirdPartyPubKey *PublicKey,
	key *KeyPair,
) ([]byte, error) {
	var nonce [NonceLen]byte
	if _, err := rand.Read(nonce[:]); err != nil {
		return nil, errgo.Notef(err, "cannot generate random number for nonce")
	}
	plain := caveatRecord{
		RootKey:   rootKey,
		Condition: condition,
	}
	plainData, err := json.Marshal(&plain)
	if err != nil {
		return nil, errgo.Notef(err, "cannot marshal %#v", &plain)
	}
	sealed := box.Seal(nil, plainData, &nonce, thirdPartyPubKey.boxKey(), key.Private.boxKey())
	id := caveatJSON{
		ThirdPartyPublicKey: thirdPartyPubKey,
		FirstPartyPublicKey: &key.Public,
		Nonce:               nonce[:],
		Id:                  base64.StdEncoding.EncodeToString(sealed),
	}
	data, err := json.Marshal(id)
	if err != nil {
		return nil, errgo.Notef(err, "cannot marshal %#v", id)
	}
	buf := make([]byte, base64.StdEncoding.EncodedLen(len(data)))
	base64.StdEncoding.Encode(buf, data)
	return buf, nil
}
func encodeCaveatV1 ( condition string , rootKey [ ] byte , thirdPartyPubKey * PublicKey , key * KeyPair , ) ( [ ] byte , error ) { var nonce [ NonceLen ] byte if _ , err := rand . Read ( nonce [ : ] ) ; err != nil { return nil , errgo . Notef ( err , " " ) } plain := caveatRecord { RootKey : rootKey , Condition : condition , } plainData , err := json . Marshal ( & plain ) if err != nil { return nil , errgo . Notef ( err , " " , & plain ) } sealed := box . Seal ( nil , plainData , & nonce , thirdPartyPubKey . boxKey ( ) , key . Private . boxKey ( ) ) id := caveatJSON { ThirdPartyPublicKey : thirdPartyPubKey , FirstPartyPublicKey : & key . Public , Nonce : nonce [ : ] , Id : base64 . StdEncoding . EncodeToString ( sealed ) , } data , err := json . Marshal ( id ) if err != nil { return nil , errgo . Notef ( err , " " , id ) } buf := make ( [ ] byte , base64 . StdEncoding . EncodedLen ( len ( data ) ) ) base64 . StdEncoding . Encode ( buf , data ) return buf , nil }
encodeCaveatV1 creates a JSON-encoded third-party caveat
with the given condtion and root key.
encodeCaveatV1 creates a JSON - encoded third - party caveat with the given condtion and root key .