// GoCaveat converts the provided Java Caveat into a Go Caveat. func GoCaveat(env jutil.Env, jCav jutil.Object) (security.Caveat, error) { // NOTE(spetrovic): We could call GoVomCopy here, but it's painfully slow and this code is // on the critical path. // Copy the Id field. jId, err := jutil.CallObjectMethod(env, jCav, "getId", nil, idSign) if err != nil { return security.Caveat{}, err } idBytes, err := jutil.CallByteArrayMethod(env, jId, "toPrimitiveArray", nil) if err != nil { return security.Caveat{}, err } var id uniqueid.Id copy(id[:], idBytes[:len(id)]) // Copy the ParamVom field. paramVom, err := jutil.CallByteArrayMethod(env, jCav, "getParamVom", nil) if err != nil { return security.Caveat{}, err } return security.Caveat{ Id: id, ParamVom: paramVom, }, nil }
func (c *btReadWriteCloser) Read(b []byte) (n int, err error) { env, freeFunc := jutil.GetEnv() defer freeFunc() data, err := jutil.CallByteArrayMethod(env, c.jStream, "read", []jutil.Sign{jutil.IntSign}, len(b)) if err != nil { return 0, err } return copy(b, data), nil }
func (s *signer) PublicKey() security.PublicKey { env, freeFunc := jutil.GetEnv() defer freeFunc() publicKeySign := jutil.ClassSign("java.security.interfaces.ECPublicKey") jPublicKey, err := jutil.CallObjectMethod(env, s.jSigner, "publicKey", nil, publicKeySign) if err != nil { log.Printf("Couldn't get Java public key: %v", err) return nil } // Get the encoded version of the public key. encoded, err := jutil.CallByteArrayMethod(env, jPublicKey, "getEncoded", nil) if err != nil { log.Printf("Couldn't get encoded data for Java public key: %v", err) return nil } key, err := security.UnmarshalPublicKey(encoded) if err != nil { log.Printf("Couldn't parse Java ECDSA public key: " + err.Error()) return nil } return key }