Beispiel #1
0
func LoadRatchet(d *Daemon, name string, fillAuth func(tag, data []byte, theirAuthPublic *[32]byte), checkAuth func(tag, data, msg []byte, ourAuthPrivate *[32]byte) error) (*ratchet.Ratchet, error) {
	ratch := new(ratchet.Ratchet)
	if err := persistence.UnmarshalFromFile(d.ratchetPath(name), ratch); err != nil {
		return nil, err
	}
	ratch.FillAuth = fillAuth
	ratch.CheckAuth = checkAuth
	return ratch, nil
}
Beispiel #2
0
func AllRatchets(d *Daemon, fillAuth func(tag, data []byte, theirAuthPublic *[32]byte), checkAuth func(tag, data, msg []byte, ourAuthPrivate *[32]byte) error) ([]*ratchet.Ratchet, error) {
	files, err := ioutil.ReadDir(d.ratchetKeysDir())
	if err != nil {
		return nil, err
	}
	ret := make([]*ratchet.Ratchet, 0, len(files))
	for _, file := range files {
		if file.IsDir() {
			continue
		}
		ratch := new(ratchet.Ratchet)
		err := persistence.UnmarshalFromFile(filepath.Join(d.ratchetKeysDir(), file.Name()), ratch)
		if err != nil {
			return nil, fmt.Errorf("failed to parse ratchet for \"%s\": %s", file.Name(), err)
		}
		ratch.FillAuth = fillAuth
		ratch.CheckAuth = checkAuth
		ret = append(ret, ratch)
	}
	return ret, nil
}