예제 #1
0
파일: map.go 프로젝트: utamaro/gogotelehash
func (p PrivateKeys) MarshalJSON() ([]byte, error) {
	type pair struct {
		Pub string `json:"pub,omitempty"`
		Prv string `json:"prv,omitempty"`
	}

	m := make(map[string]pair, len(p))
	for k, v := range p {
		m[hex.EncodeToString([]byte{k})] = pair{
			Pub: base32util.EncodeToString(v.Public()),
			Prv: base32util.EncodeToString(v.Private()),
		}
	}

	return json.Marshal(m)
}
예제 #2
0
// FromKeyAndIntermediates derives a hasname from a public key and some intermediate parts.
func FromKeyAndIntermediates(id uint8, key []byte, intermediates cipherset.Parts) (H, error) {
	var (
		all          = make(cipherset.Parts, len(intermediates)+1)
		sum          = sha256.Sum256(key)
		intermediate = base32util.EncodeToString(sum[:])
	)

	for k, v := range intermediates {
		all[k] = v
	}
	all[id] = intermediate

	return FromIntermediates(all)
}
예제 #3
0
// PartsFromKeys derives the intermediate parts from their respectve public keys.
func PartsFromKeys(keys cipherset.Keys) cipherset.Parts {
	var (
		hash          = sha256.New()
		intermediates = make(cipherset.Parts, len(keys))
		buf           [32]byte
	)

	for id, key := range keys {
		hash.Write(key.Public())
		hash.Sum(buf[:0])
		hash.Reset()

		intermediates[id] = base32util.EncodeToString(buf[:])[:52]
	}

	return intermediates
}
예제 #4
0
// 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
}
예제 #5
0
파일: map.go 프로젝트: utamaro/gogotelehash
func (o opaqueKey) String() string {
	return base32util.EncodeToString(o.pub)
}
예제 #6
0
func (k *key) String() string {
	return base32util.EncodeToString((*k.pub)[:])
}
예제 #7
0
파일: key.go 프로젝트: utamaro/gogotelehash
func (k *key) String() string {
	return base32util.EncodeToString(k.Public())
}