示例#1
0
文件: util.go 项目: vanadium/go.jni
// JavaCaveat converts the provided Go Caveat into a Java Caveat.
func JavaCaveat(env jutil.Env, caveat security.Caveat) (jutil.Object, error) {
	// NOTE(spetrovic): We could call JVomCopy here, but it's painfully slow and this code is
	// on the critical path.

	// Copy the Id field.
	jId, err := jutil.NewObject(env, jIdClass, []jutil.Sign{jutil.ByteArraySign}, []byte(caveat.Id[:]))
	if err != nil {
		return jutil.NullObject, err
	}
	return jutil.NewObject(env, jCaveatClass, []jutil.Sign{idSign, jutil.ByteArraySign}, jId, caveat.ParamVom)
}
示例#2
0
文件: jni.go 项目: vanadium/go.jni
//export Java_io_v_v23_security_VPrincipalImpl_nativeCreatePersistentForSigner
func Java_io_v_v23_security_VPrincipalImpl_nativeCreatePersistentForSigner(jenv *C.JNIEnv, jclass C.jclass, jSigner C.jobject, jDir C.jstring) C.jobject {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	signerObj := jutil.Object(uintptr(unsafe.Pointer(jSigner)))
	signer, err := GoSigner(env, signerObj)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	dir := jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jDir))))
	stateSerializer, err := vsecurity.NewPrincipalStateSerializer(dir)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	principal, err := vsecurity.NewPrincipalFromSigner(signer, stateSerializer)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	ref := jutil.GoNewRef(&principal) // Un-refed when the Java VPrincipalImpl is finalized.
	jPrincipal, err := jutil.NewObject(env, jVPrincipalImplClass, []jutil.Sign{jutil.LongSign, signerSign, blessingStoreSign, blessingRootsSign}, int64(ref), signerObj, jutil.NullObject, jutil.NullObject)
	if err != nil {
		jutil.GoDecRef(ref)
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobject(unsafe.Pointer(jPrincipal))
}
示例#3
0
文件: jni.go 项目: vanadium/go.jni
//export Java_io_v_v23_security_VSecurity_nativeCreateAuthorizer
func Java_io_v_v23_security_VSecurity_nativeCreateAuthorizer(jenv *C.JNIEnv, jVSecurityClass C.jclass, kind C.jint, jKey C.jobject) C.jobject {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	var auth security.Authorizer
	switch kind {
	case 0:
		auth = security.AllowEveryone()
	case 1:
		auth = security.EndpointAuthorizer()
	case 2:
		auth = security.DefaultAuthorizer()
	case 3:
		key, err := GoPublicKey(env, jutil.Object(uintptr(unsafe.Pointer(jKey))))
		if err != nil {
			jutil.JThrowV(env, err)
			return nil
		}
		auth = security.PublicKeyAuthorizer(key)
	default:
		return nil
	}
	ref := jutil.GoNewRef(&auth) // Un-refed when the Java PermissionsAuthorizer is finalized
	jAuthorizer, err := jutil.NewObject(env, jutil.Class(uintptr(unsafe.Pointer(jPermissionsAuthorizerClass))), []jutil.Sign{jutil.LongSign}, int64(ref))
	if err != nil {
		jutil.GoDecRef(ref)
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobject(unsafe.Pointer(jAuthorizer))
}
示例#4
0
文件: driver.go 项目: vanadium/go.jni
func initDriverFactory(env jutil.Env) error {
	jDriverClass, err := jutil.JFindClass(env, "io/v/android/impl/google/discovery/plugins/ble/Driver")
	if err != nil {
		return err
	}
	factory := func(ctx *context.T, _ string) (ble.Driver, error) {
		env, freeFunc := jutil.GetEnv()
		defer freeFunc()

		jCtx, err := jcontext.JavaContext(env, ctx, nil)
		if err != nil {
			return nil, err
		}
		jDriver, err := jutil.NewObject(env, jDriverClass, []jutil.Sign{contextSign}, jCtx)
		if err != nil {
			return nil, err
		}
		// Reference the driver; it will be de-referenced when the driver is garbage-collected.
		jDriver = jutil.NewGlobalRef(env, jDriver)
		d := &driver{jDriver}
		runtime.SetFinalizer(d, func(*driver) {
			env, freeFunc := jutil.GetEnv()
			jutil.DeleteGlobalRef(env, d.jDriver)
			freeFunc()
		})
		return d, nil
	}
	ble.SetDriverFactory(factory)
	return nil
}
示例#5
0
文件: jni.go 项目: vanadium/go.jni
//export Java_io_v_v23_security_access_PermissionsAuthorizer_nativeCreate
func Java_io_v_v23_security_access_PermissionsAuthorizer_nativeCreate(jenv *C.JNIEnv, jPermissionsAuthorizerClass C.jclass, jPermissions C.jobject, jTagType C.jobject) C.jobject {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	perms, err := GoPermissions(env, jutil.Object(uintptr(unsafe.Pointer(jPermissions))))
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	tagType, err := jutil.GoVdlType(env, jutil.Object(uintptr(unsafe.Pointer(jTagType))))
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	authorizer, err := access.PermissionsAuthorizer(perms, tagType)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	ref := jutil.GoNewRef(&authorizer) // Un-refed when the Java PermissionsAuthorizer is finalized
	jAuthorizer, err := jutil.NewObject(env, jutil.Class(uintptr(unsafe.Pointer(jPermissionsAuthorizerClass))), []jutil.Sign{jutil.LongSign}, int64(ref))
	if err != nil {
		jutil.GoDecRef(ref)
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobject(unsafe.Pointer(jAuthorizer))
}
示例#6
0
文件: util.go 项目: vanadium/go.jni
// javaUUID converts a Go UUID into a Java UUID instance.
func javaUUID(env jutil.Env, uuid idiscovery.Uuid) (jutil.Object, error) {
	var high, low int64
	buf := bytes.NewReader(uuid)
	binary.Read(buf, binary.BigEndian, &high)
	binary.Read(buf, binary.BigEndian, &low)
	return jutil.NewObject(env, jUUIDClass, []jutil.Sign{jutil.LongSign, jutil.LongSign}, high, low)
}
示例#7
0
文件: util.go 项目: vanadium/go.jni
// JavaPublisherEntry converts the provided rpc.PublisherEntry value into a Java
// PublisherEntry object.
// TODO(suharshs): Add PublisherState to the java publisher entry? May not make sense, since there is no
// notification channel in Java.
func JavaPublisherEntry(env jutil.Env, entry rpc.PublisherEntry) (jutil.Object, error) {
	jStatus, err := jutil.NewObject(env, jPublisherEntryClass, []jutil.Sign{jutil.StringSign, jutil.StringSign, jutil.DateTimeSign, jutil.VExceptionSign, jutil.DurationSign, jutil.DateTimeSign, jutil.VExceptionSign}, entry.Name, entry.Server, entry.LastMount, entry.LastMountErr, entry.TTL, entry.LastUnmount, entry.LastUnmountErr)
	if err != nil {
		return jutil.NullObject, err
	}
	return jStatus, nil
}
示例#8
0
文件: util.go 项目: vanadium/go.jni
// javaStream converts the provided Go stream into a Java Stream object.
func javaStream(env jutil.Env, jContext jutil.Object, stream rpc.Stream) (jutil.Object, error) {
	ref := jutil.GoNewRef(&stream) // Un-refed when the Java stream object is finalized.
	jStream, err := jutil.NewObject(env, jStreamImplClass, []jutil.Sign{contextSign, jutil.LongSign}, jContext, int64(ref))
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jStream, nil
}
示例#9
0
文件: util.go 项目: vanadium/go.jni
// JavaAddressChooser converts a Go address chooser function into a Java
// AddressChooser object.
func JavaAddressChooser(env jutil.Env, chooser rpc.AddressChooser) (jutil.Object, error) {
	ref := jutil.GoNewRef(&chooser) // Un-refed when the Java AddressChooser object is finalized.
	jAddressChooser, err := jutil.NewObject(env, jAddressChooserImplClass, []jutil.Sign{jutil.LongSign}, int64(ref))
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jAddressChooser, nil
}
示例#10
0
文件: util.go 项目: vanadium/go.jni
// JavaServerCall converts a Go rpc.ServerCall into a Java ServerCall object.
func JavaServerCall(env jutil.Env, serverCall rpc.ServerCall) (jutil.Object, error) {
	ref := jutil.GoNewRef(&serverCall) // Un-refed when the Java ServerCall object is finalized.
	jServerCall, err := jutil.NewObject(env, jServerCallImplClass, []jutil.Sign{jutil.LongSign}, int64(ref))
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jServerCall, nil
}
示例#11
0
文件: util.go 项目: vanadium/go.jni
// JavaBlessingPattern converts the provided Go BlessingPattern into Java
// BlessingPattern.
func JavaBlessingPattern(env jutil.Env, pattern security.BlessingPattern) (jutil.Object, error) {
	ref := jutil.GoNewRef(&pattern) // Un-refed when the Java BlessingRootsImpl is finalized.
	jPattern, err := jutil.NewObject(env, jBlessingPatternClass, []jutil.Sign{jutil.LongSign, jutil.StringSign}, int64(ref), string(pattern))
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jPattern, nil
}
示例#12
0
文件: call.go 项目: vanadium/go.jni
// JavaCall converts the provided Go (security) Call into a Java Call object.
func JavaCall(env jutil.Env, call security.Call) (jutil.Object, error) {
	ref := jutil.GoNewRef(&call) // Un-refed when the Java CallImpl object is finalized.
	jCall, err := jutil.NewObject(env, jCallImplClass, []jutil.Sign{jutil.LongSign}, int64(ref))
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jCall, nil
}
示例#13
0
文件: util.go 项目: vanadium/go.jni
// JavaDiscovery converts a Go discovery instance into a Java discovery instance.
func JavaDiscovery(env jutil.Env, d discovery.T) (jutil.Object, error) {
	ref := jutil.GoNewRef(&d) // Un-refed when jDiscovery is finalized.
	jDiscovery, err := jutil.NewObject(env, jDiscoveryImplClass, []jutil.Sign{jutil.LongSign}, int64(ref))
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jDiscovery, nil
}
示例#14
0
文件: roots.go 项目: vanadium/go.jni
// JavaBlessingRoots creates an instance of Java BlessingRoots that uses the provided Go
// BlessingRoots as its underlying implementation.
func JavaBlessingRoots(env jutil.Env, roots security.BlessingRoots) (jutil.Object, error) {
	ref := jutil.GoNewRef(&roots) // Un-refed when the Java BlessingRootsImpl is finalized.
	jRoots, err := jutil.NewObject(env, jBlessingRootsImplClass, []jutil.Sign{jutil.LongSign}, int64(ref))
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jRoots, nil
}
示例#15
0
文件: store.go 项目: vanadium/go.jni
// JavaBlessingStore creates an instance of Java BlessingStore that uses the provided Go
// BlessingStore as its underlying implementation.
func JavaBlessingStore(env jutil.Env, store security.BlessingStore) (jutil.Object, error) {
	ref := jutil.GoNewRef(&store) // Un-refed when the Java BlessingStoreImpl is finalized.
	jObj, err := jutil.NewObject(env, jBlessingStoreImplClass, []jutil.Sign{jutil.LongSign}, int64(ref))
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jObj, nil
}
示例#16
0
// JavaPrincipal converts the provided Go Principal into a Java VPrincipal
// object.
func JavaPrincipal(env jutil.Env, principal security.Principal) (jutil.Object, error) {
	if principal == nil {
		return jutil.NullObject, nil
	}
	ref := jutil.GoNewRef(&principal) // Un-refed when the Java VPrincipalImpl is finalized.
	jPrincipal, err := jutil.NewObject(env, jVPrincipalImplClass, []jutil.Sign{jutil.LongSign, signerSign, blessingStoreSign, blessingRootsSign}, int64(ref), jutil.NullObject, jutil.NullObject, jutil.NullObject)
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jPrincipal, nil
}
示例#17
0
文件: util.go 项目: vanadium/go.jni
// JavaClient converts the provided Go client into a Java Client object.
func JavaClient(env jutil.Env, client rpc.Client) (jutil.Object, error) {
	if client == nil {
		return jutil.NullObject, nil
	}
	ref := jutil.GoNewRef(&client) // Un-refed when the Java Client object is finalized.
	jClient, err := jutil.NewObject(env, jClientImplClass, []jutil.Sign{jutil.LongSign}, int64(ref))
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jClient, nil
}
示例#18
0
文件: util.go 项目: vanadium/go.jni
// JavaServer converts the provided Go Server into a Java Server object.
func JavaServer(env jutil.Env, server rpc.Server) (jutil.Object, error) {
	if server == nil {
		return jutil.NullObject, fmt.Errorf("Go Server value cannot be nil")
	}
	ref := jutil.GoNewRef(&server) // Un-refed when the Java Server object is finalized.
	jServer, err := jutil.NewObject(env, jServerImplClass, []jutil.Sign{jutil.LongSign}, int64(ref))
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jServer, nil
}
示例#19
0
文件: jni.go 项目: vanadium/go.jni
func handleInvite(invite discovery.Invite, handler jutil.Object) error {
	env, free := jutil.GetEnv()
	defer free()
	jInvite, err := jutil.NewObject(env, jInviteClass,
		[]jutil.Sign{jutil.StringSign, jutil.StringSign},
		invite.Syncgroup.Blessing, invite.Syncgroup.Name)
	if err != nil {
		return err
	}
	return jutil.CallVoidMethod(env, handler, "handleInvite",
		[]jutil.Sign{inviteSign}, jInvite)
}
示例#20
0
文件: util.go 项目: vanadium/go.jni
// JavaNamespace converts the provided Go Namespace into a Java Namespace
// object.
func JavaNamespace(env jutil.Env, namespace namespace.T) (jutil.Object, error) {
	if namespace == nil {
		return jutil.NullObject, nil
	}
	ref := jutil.GoNewRef(&namespace) // Un-refed when the Java NamespaceImpl is finalized.
	jNamespace, err := jutil.NewObject(env, jNamespaceImplClass, []jutil.Sign{jutil.LongSign}, int64(ref))
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jNamespace, nil
}
示例#21
0
文件: util.go 项目: vanadium/go.jni
// JavaInputChannel creates a new Java InputChannel object given the provided Go recv function.
//
// All objects returned by the recv function must be globally references.
//
// The recv function must return verror.ErrEndOfFile when there are no more elements
// to receive.
func JavaInputChannel(env jutil.Env, ctx *context.T, ctxCancel func(), recv func() (jutil.Object, error)) (jutil.Object, error) {
	jContext, err := jcontext.JavaContext(env, ctx, ctxCancel)
	if err != nil {
		return jutil.NullObject, err
	}
	ref := jutil.GoNewRef(&recv) // Un-refed when jInputChannel is finalized.
	jInputChannel, err := jutil.NewObject(env, jInputChannelImplClass, []jutil.Sign{contextSign, jutil.LongSign}, jContext, int64(ref))
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jInputChannel, nil
}
示例#22
0
文件: util.go 项目: vanadium/go.jni
// javaUpdate converts a Go update instance into a Java update instance.
func javaUpdate(env jutil.Env, update discovery.Update) (jutil.Object, error) {
	jAd, err := jutil.JVomCopy(env, update.Advertisement(), jAdvertisementClass)
	if err != nil {
		return jutil.NullObject, err
	}
	ref := jutil.GoNewRef(&update) // Un-refed when jUpdate is finalized.
	jUpdate, err := jutil.NewObject(env, jUpdateImplClass, []jutil.Sign{jutil.LongSign, jutil.BoolSign, advertisementSign, jutil.LongSign},
		int64(ref), update.IsLost(), jAd, update.Timestamp().UnixNano())
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jUpdate, nil
}
示例#23
0
文件: util.go 项目: vanadium/go.jni
// GoListenSpec converts the provided Go ListenSpec into a Java ListenSpec.
func JavaListenSpec(env jutil.Env, spec rpc.ListenSpec) (jutil.Object, error) {
	jAddrs, err := JavaListenAddrArray(env, spec.Addrs)
	if err != nil {
		return jutil.NullObject, err
	}
	jChooser, err := JavaAddressChooser(env, spec.AddressChooser)
	if err != nil {
		return jutil.NullObject, err
	}
	addressSign := jutil.ClassSign("io.v.v23.rpc.ListenSpec$Address")
	jSpec, err := jutil.NewObject(env, jListenSpecClass, []jutil.Sign{jutil.ArraySign(addressSign), jutil.StringSign, addressChooserSign}, jAddrs, spec.Proxy, jChooser)
	if err != nil {
		return jutil.NullObject, err
	}
	return jSpec, nil
}
示例#24
0
文件: util.go 项目: vanadium/go.jni
// JavaContext converts the provided Go Context into a Java VContext.
// If the provided cancel function is nil, Java VContext won't be
// cancelable.
func JavaContext(env jutil.Env, ctx *context.T, cancel context.CancelFunc) (jutil.Object, error) {
	ctxRef := jutil.GoNewRef(ctx) // Un-refed when the Java context object is finalized.
	cancelRef := jutil.NullRef
	if cancel != nil {
		cancelRef = jutil.GoNewRef(&cancel) // Un-refed when the Java context object is finalized.
	}
	jCtx, err := jutil.NewObject(env, jVContextClass, []jutil.Sign{jutil.LongSign, jutil.LongSign}, int64(ctxRef), int64(cancelRef))
	if err != nil {
		jutil.GoDecRef(ctxRef)
		if cancel != nil {
			jutil.GoDecRef(cancelRef)
		}
		return jutil.NullObject, err
	}
	return jCtx, err
}
示例#25
0
文件: util.go 项目: vanadium/go.jni
// javaCall converts the provided Go Call value into a Java Call object.
func javaCall(env jutil.Env, jContext jutil.Object, call rpc.ClientCall) (jutil.Object, error) {
	if call == nil {
		return jutil.NullObject, fmt.Errorf("Go Call value cannot be nil")
	}
	jStream, err := javaStream(env, jContext, call)
	if err != nil {
		return jutil.NullObject, err
	}
	ref := jutil.GoNewRef(&call) // Un-refed when the Java Call object is finalized.
	jCall, err := jutil.NewObject(env, jClientCallImplClass, []jutil.Sign{contextSign, jutil.LongSign, streamSign}, jContext, int64(ref), jStream)
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jCall, nil
}
示例#26
0
文件: util.go 项目: vanadium/go.jni
// JavaOutputChannel creates a new Java OutputChannel object given the provided Go convert, send
// and close functions. Send is invoked with the result of convert, which must be non-blocking.
func JavaOutputChannel(env jutil.Env, ctx *context.T, ctxCancel func(), convert func(jutil.Object) (interface{}, error), send func(interface{}) error, close func() error) (jutil.Object, error) {
	jContext, err := jcontext.JavaContext(env, ctx, ctxCancel)
	if err != nil {
		return jutil.NullObject, err
	}
	convertRef := jutil.GoNewRef(&convert) // Un-refed when jOutputChannel is finalized.
	sendRef := jutil.GoNewRef(&send)       // Un-refed when jOutputChannel is finalized.
	closeRef := jutil.GoNewRef(&close)     // Un-refed when jOutputChannel is finalized.
	jOutputChannel, err := jutil.NewObject(env, jOutputChannelImplClass, []jutil.Sign{contextSign, jutil.LongSign, jutil.LongSign, jutil.LongSign}, jContext, int64(convertRef), int64(sendRef), int64(closeRef))
	if err != nil {
		jutil.GoDecRef(convertRef)
		jutil.GoDecRef(sendRef)
		jutil.GoDecRef(closeRef)
		return jutil.NullObject, err
	}
	return jOutputChannel, nil
}
示例#27
0
文件: driver.go 项目: vanadium/go.jni
func (d *driver) StartScan(uuids []string, baseUuid, maskUuid string, handler ble.ScanHandler) error {
	env, freeFunc := jutil.GetEnv()
	defer freeFunc()

	handlerRef := jutil.GoNewRef(&handler) // Un-refed when jNativeScanHandler is finalized.
	jNativeScanHandler, err := jutil.NewObject(env, jNativeScanHandlerClass, []jutil.Sign{jutil.LongSign}, int64(handlerRef))
	if err != nil {
		jutil.GoDecRef(handlerRef)
		return err
	}
	err = jutil.CallVoidMethod(env, d.jDriver, "startScan", []jutil.Sign{jutil.ArraySign(jutil.StringSign), jutil.StringSign, jutil.StringSign, scanHandlerSign}, uuids, baseUuid, maskUuid, jNativeScanHandler)
	if err != nil {
		jutil.GoDecRef(handlerRef)
		return err
	}
	return nil
}
示例#28
0
文件: util.go 项目: vanadium/go.jni
// javaStreamServerCall converts the provided Go serverCall into a Java StreamServerCall
// object.
func javaStreamServerCall(env jutil.Env, jContext jutil.Object, call rpc.StreamServerCall) (jutil.Object, error) {
	if call == nil {
		return jutil.NullObject, fmt.Errorf("Go StreamServerCall value cannot be nil")
	}
	jStream, err := javaStream(env, jContext, call)
	if err != nil {
		return jutil.NullObject, err
	}
	jServerCall, err := JavaServerCall(env, call)
	if err != nil {
		return jutil.NullObject, err
	}
	serverCallSign := jutil.ClassSign("io.v.v23.rpc.ServerCall")
	ref := jutil.GoNewRef(&call) // Un-refed when the Java StreamServerCall object is finalized.
	jStreamServerCall, err := jutil.NewObject(env, jStreamServerCallImplClass, []jutil.Sign{jutil.LongSign, streamSign, serverCallSign}, int64(ref), jStream, jServerCall)
	if err != nil {
		jutil.GoDecRef(ref)
		return jutil.NullObject, err
	}
	return jStreamServerCall, nil
}
示例#29
0
文件: jni.go 项目: vanadium/go.jni
//export Java_io_v_v23_security_VPrincipalImpl_nativeCreateForAll
func Java_io_v_v23_security_VPrincipalImpl_nativeCreateForAll(jenv *C.JNIEnv, jclass C.jclass, jSigner C.jobject, jStore C.jobject, jRoots C.jobject) C.jobject {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	signerObj := jutil.Object(uintptr(unsafe.Pointer(jSigner)))
	storeObj := jutil.Object(uintptr(unsafe.Pointer(jStore)))
	rootsObj := jutil.Object(uintptr(unsafe.Pointer(jRoots)))
	signer, err := GoSigner(env, signerObj)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	store, err := GoBlessingStore(env, storeObj)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	roots, err := GoBlessingRoots(env, rootsObj)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	// TODO(ataly): Implement BlessingsBasedEncrypter and BlessingsBasedDecrypter types
	// in Java.
	principal, err := security.CreatePrincipal(signer, store, roots)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	ref := jutil.GoNewRef(&principal) // Un-refed when the Java VPrincipalImpl is finalized.
	jPrincipal, err := jutil.NewObject(env, jVPrincipalImplClass, []jutil.Sign{jutil.LongSign, signerSign, blessingStoreSign, blessingRootsSign}, int64(ref), signerObj, storeObj, rootsObj)
	if err != nil {
		jutil.GoDecRef(ref)
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobject(unsafe.Pointer(jPrincipal))
}
示例#30
0
文件: util.go 项目: vanadium/go.jni
// JavaNetworkAddress converts a Go net.Addr into a Java NetworkAddress object.
func JavaNetworkAddress(env jutil.Env, addr net.Addr) (jutil.Object, error) {
	return jutil.NewObject(env, jNetworkAddressClass, []jutil.Sign{jutil.StringSign, jutil.StringSign}, addr.Network(), addr.String())
}