func DecodeKey(csid uint8, pub, prv string) (Key, error) { c := ciphers[csid] pubKey, err := base32util.DecodeString(pub) if err != nil { return nil, ErrInvalidKey } prvKey, err := base32util.DecodeString(prv) if err != nil { return nil, ErrInvalidKey } if c == nil { return opaqueKey{csid, pubKey, prvKey}, nil } return c.DecodeKeyBytes(pubKey, prvKey) }
// FromIntermediates derives a hashname from its intermediate parts. func FromIntermediates(parts cipherset.Parts) (H, error) { if len(parts) == 0 { return "", ErrNoIntermediateParts } var ( hash = sha256.New() ids = make([]int, 0, len(parts)) buf [32]byte ) for id := range parts { ids = append(ids, int(id)) } sort.Ints(ids) for _, id := range ids { // decode intermediate part partString := parts[uint8(id)] if len(partString) != 52 { return "", ErrInvalidIntermediatePart } part, err := base32util.DecodeString(partString) if err != nil { return "", ErrInvalidIntermediatePart } buf[0] = byte(id) hash.Write(buf[:1]) hash.Sum(buf[:0]) hash.Reset() hash.Write(buf[:32]) hash.Write(part) hash.Sum(buf[:0]) hash.Reset() hash.Write(buf[:32]) } return H(base32util.EncodeToString(buf[:32])), nil }