// procUID allows to process a sender UID from the header in parallel. // senderUID is the JSON encoded UID message parsed from the header, res is // the result channel used to communicate the result of the calculation. func procUID(senderUID string, res chan *procUIDResult) { var r procUIDResult var err error r.uidIndex = cipher.SHA256(cipher.SHA256([]byte(senderUID))) r.msg, err = uid.NewJSON(senderUID) if err != nil { res <- &procUIDResult{uidIndex: nil, msg: nil, err: err} return } // return results res <- &r }
// GetPrivateUID gets a private uid for identity from keyDB. // // TODO: get all UID messages for given identity which are not expired. func (keyDB *KeyDB) GetPrivateUID( identity string, withPrivkeys bool, ) (*uid.Message, *uid.MessageReply, error) { var ( uidJSON string sigPrivKey string encPrivKey string replyJSON string ) err := keyDB.getPrivateUIDQuery.QueryRow(identity).Scan(&uidJSON, &sigPrivKey, &encPrivKey, &replyJSON) switch { case err == sql.ErrNoRows: return nil, nil, log.Errorf("keydb: no privkey for nym '%s' found", identity) case err != nil: return nil, nil, log.Error(err) default: msg, err := uid.NewJSON(uidJSON) if err != nil { return nil, nil, err } if err := msg.VerifySelfSig(); err != nil { // if this fails something is seriously wrong return nil, nil, log.Error(err) } if withPrivkeys { if err := msg.SetPrivateSigKey(sigPrivKey); err != nil { return nil, nil, err } if err := msg.SetPrivateEncKey(encPrivKey); err != nil { return nil, nil, err } } var msgReply *uid.MessageReply if replyJSON != "" { msgReply, err = uid.NewJSONReply(replyJSON) if err != nil { return nil, nil, err } } return msg, msgReply, nil } }
// GetPublicUID gets the public UID message from keyDB with the highest // position smaller or equal to maxpos. func (keyDB *KeyDB) GetPublicUID( identity string, maxpos uint64, ) (msg *uid.Message, pos uint64, found bool, err error) { var uidJSON string err = keyDB.getPublicUIDQuery.QueryRow(identity, maxpos).Scan(&uidJSON, &pos) switch { case err == sql.ErrNoRows: return nil, 0, false, nil case err != nil: return nil, 0, false, log.Error(err) default: msg, err = uid.NewJSON(uidJSON) if err != nil { return nil, 0, false, err } found = true return } }