func (r *PrivateKeySetRepo) Set(ks key.KeySet) error { qt := r.quote(keyTableName) tx, err := r.begin() if err != nil { return err } defer tx.Rollback() exec := r.executor(tx) if _, err := exec.Exec(fmt.Sprintf("DELETE FROM %s", qt)); err != nil { return err } pks, ok := ks.(*key.PrivateKeySet) if !ok { return errors.New("unable to cast to PrivateKeySet") } m, err := newPrivateKeySetModel(pks) if err != nil { return err } j, err := json.Marshal(m) if err != nil { return err } var v []byte if r.useOldFormat { v, err = pcrypto.AESEncrypt(j, r.active()) } else { v, err = pcrypto.Encrypt(j, r.active()) } if err != nil { return err } b := &privateKeySetBlob{Value: v} if err := exec.Insert(b); err != nil { return err } return tx.Commit() }
func (r *PrivateKeySetRepo) Set(ks key.KeySet) error { qt := pq.QuoteIdentifier(keyTableName) _, err := r.dbMap.Exec(fmt.Sprintf("DELETE FROM %s", qt)) if err != nil { return err } pks, ok := ks.(*key.PrivateKeySet) if !ok { return errors.New("unable to cast to PrivateKeySet") } m, err := newPrivateKeySetModel(pks) if err != nil { return err } j, err := json.Marshal(m) if err != nil { return err } var v []byte if r.useOldFormat { v, err = pcrypto.AESEncrypt(j, r.active()) } else { v, err = pcrypto.Encrypt(j, r.active()) } if err != nil { return err } b := &privateKeySetBlob{Value: v} return r.dbMap.Insert(b) }