Beispiel #1
0
// JavaPublicKey converts the provided Go PublicKey into Java PublicKey.
func JavaPublicKey(env jutil.Env, key security.PublicKey) (jutil.Object, error) {
	if key == nil {
		return jutil.NullObject, nil
	}
	der, err := key.MarshalBinary()
	if err != nil {
		return jutil.NullObject, err
	}
	return JavaPublicKeyFromDER(env, der)
}
Beispiel #2
0
func selectColor(key security.PublicKey) Color {
	var (
		bytes, _ = key.MarshalBinary()
		uid      = md5.Sum(bytes)
		pick     = func(idx int) float32 {
			//  Keep component between [30, 225] instead of [0,255]
			// to avoid white and black - and then normalize to [0, 1]
			return (30 + (float32(uid[idx])/255.0)*(225-30)) / 255
		}
	)
	// Consider md5 to have uniform randomness in all its bytes.
	// We're just selecting a color, no need to fret if it doesn't.
	return Color{R: pick(0), G: pick(7), B: pick(15)}
}