Example #1
0
func KeyFromString(s string) (*BoxKey, error) {
	key := new(BoxKey)
	b, err := base32.DecodeString(s)
	if err != nil {
		return nil, fmt.Errorf("base32 decode error: %s", err)
	}
	if copy(key[:], b) < 32 {
		return nil, fmt.Errorf("short key")
	}
	return key, nil
}
Example #2
0
func (k *BoxKey) UnmarshalJSON(b []byte) error {
	var s string
	if err := json.Unmarshal(b, &s); err != nil {
		return err
	}
	bs, err := base32.DecodeString(s)
	if err != nil {
		return fmt.Errorf("base32 decode error: %s", err)
	}
	if copy(k[:], bs) < 32 {
		return fmt.Errorf("short key")
	}
	return nil
}