func (w *Worker) updatePrimaryUat(tx *sqlx.Tx, pubkey *Pubkey, r *UserAttribute) error { if pubkey.PrimaryUat.String == r.ScopedDigest { if _, err := tx.Execv(` UPDATE openpgp_pubkey SET primary_uat = $1 WHERE uuid = $2`, r.ScopedDigest, pubkey.RFingerprint); err != nil { return err } } return nil }
func (w *Worker) updateUatRevsig(tx *sqlx.Tx, uat *UserAttribute, r *Signature) error { if uat.RevSigDigest.String == r.ScopedDigest { if _, err := tx.Execv(` UPDATE openpgp_uat SET revsig_uuid = $1 WHERE uuid = $2`, r.ScopedDigest, uat.ScopedDigest); err != nil { return err } } return nil }
func (w *Worker) updateSubkeyRevsig(tx *sqlx.Tx, subkey *Subkey, r *Signature) error { if subkey.RevSigDigest.String == r.ScopedDigest { if _, err := tx.Execv(` UPDATE openpgp_subkey SET revsig_uuid = $1 WHERE uuid = $2`, r.ScopedDigest, subkey.RFingerprint); err != nil { return err } } return nil }
func (l *Loader) insertUat(tx *sqlx.Tx, pubkey *Pubkey, r *UserAttribute) error { _, err := tx.Execv(l.insertSelectFrom(` INSERT INTO openpgp_uat ( uuid, creation, expiration, state, packet, pubkey_uuid, revsig_uuid) SELECT $1, $2, $3, $4, $5, $6, $7`, "openpgp_uat", "uuid = $1"), r.ScopedDigest, r.Creation, r.Expiration, r.State, r.Packet, pubkey.RFingerprint, r.RevSigDigest) return err }
func (l *Loader) insertUid(tx *sqlx.Tx, pubkey *Pubkey, r *UserId) error { _, err := tx.Execv(l.insertSelectFrom(` INSERT INTO openpgp_uid ( uuid, creation, expiration, state, packet, pubkey_uuid, revsig_uuid, keywords, keywords_fulltext) SELECT $1, $2, $3, $4, $5, $6, $7, $8, to_tsvector($8)`, "openpgp_uid", "uuid = $1"), r.ScopedDigest, r.Creation, r.Expiration, r.State, r.Packet, pubkey.RFingerprint, r.RevSigDigest, util.CleanUtf8(r.Keywords)) return err }
func (l *Loader) insertSubkey(tx *sqlx.Tx, pubkey *Pubkey, r *Subkey) error { _, err := tx.Execv(l.insertSelectFrom(` INSERT INTO openpgp_subkey ( uuid, creation, expiration, state, packet, pubkey_uuid, revsig_uuid, algorithm, bit_len) SELECT $1, $2, $3, $4, $5, $6, $7, $8, $9`, "openpgp_subkey", "uuid = $1"), r.RFingerprint, r.Creation, r.Expiration, r.State, r.Packet, pubkey.RFingerprint, r.RevSigDigest, r.Algorithm, r.BitLen) return err }
func (l *Loader) insertSig(tx *sqlx.Tx, pubkey *Pubkey, signable PacketRecord, r *Signature) error { baseSql := ` INSERT INTO openpgp_sig ( uuid, creation, expiration, state, packet, sig_type, signer, signer_uuid%s) SELECT $1, $2, $3, $4, $5, $6, $7, $8%s` matchSql := "uuid = $1" args := []interface{}{ r.ScopedDigest, r.Creation, r.Expiration, r.State, r.Packet, r.SigType, r.RIssuerKeyId, r.RIssuerFingerprint, } var sql string switch signed := signable.(type) { case *Pubkey: sql = fmt.Sprintf(baseSql, ", pubkey_uuid", ", $9") args = append(args, signed.RFingerprint) matchSql += " AND pubkey_uuid = $9" case *Subkey: sql = fmt.Sprintf(baseSql, ", pubkey_uuid, subkey_uuid", ", $9, $10") args = append(args, pubkey.RFingerprint, signed.RFingerprint) matchSql += " AND pubkey_uuid = $9 AND subkey_uuid = $10" case *UserId: sql = fmt.Sprintf(baseSql, ", pubkey_uuid, uid_uuid", ", $9, $10") args = append(args, pubkey.RFingerprint, signed.ScopedDigest) matchSql += " AND pubkey_uuid = $9 AND uid_uuid = $10" case *UserAttribute: sql = fmt.Sprintf(baseSql, ", pubkey_uuid, uat_uuid", ", $9, $10") args = append(args, pubkey.RFingerprint, signed.ScopedDigest) matchSql += " AND pubkey_uuid = $9 AND uat_uuid = $10" case *Signature: sql = fmt.Sprintf(baseSql, ", pubkey_uuid, sig_uuid", ", $9, $10") args = append(args, pubkey.RFingerprint, signed.ScopedDigest) matchSql += " AND pubkey_uuid = $9 AND sig_uuid = $10" default: return fmt.Errorf("Unsupported packet record type: %v", signed) } _, err := tx.Execv(l.insertSelectFrom(sql, "openpgp_sig", matchSql), args...) // TODO: use RETURNING to update matched issuer fingerprint return err }
func (l *Loader) insertPubkey(tx *sqlx.Tx, r *Pubkey) error { _, err := tx.Execv(l.insertSelectFrom(` INSERT INTO openpgp_pubkey ( uuid, creation, expiration, state, packet, ctime, mtime, md5, sha256, revsig_uuid, primary_uid, primary_uat, algorithm, bit_len, unsupp) SELECT $1, $2, $3, $4, $5, now(), now(), $6, $7, $8, $9, $10, $11, $12, $13`, "openpgp_pubkey", "uuid = $1"), r.RFingerprint, r.Creation, r.Expiration, r.State, r.Packet, // TODO: use mtime and ctime from record, or use RETURNING to set it r.Md5, r.Sha256, r.RevSigDigest, r.PrimaryUid, r.PrimaryUat, r.Algorithm, r.BitLen, r.Unsupported) return err }