2
Hockeypuck - OpenPGP key server
3
Copyright (C) 2012-2014 Casey Marshall
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Affero General Public License as published by
7
the Free Software Foundation, version 3.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU Affero General Public License for more details.
14
You should have received a copy of the GNU Affero General Public License
15
along with this program. If not, see <http://www.gnu.org/licenses/>.
24
type PacketRecordMap map[string]PacketRecord
26
var ErrMissingUuid error = errors.New("Packet record missing content-unique identifier")
28
func GetUuid(rec PacketRecord) string {
29
switch r := rec.(type) {
44
func (m PacketRecordMap) Add(rec PacketRecord) error {
48
} else if _, ok := m[uuid]; !ok {
54
// Map a tree of packet objects by strong hash.
55
func MapKey(pubkey *Pubkey) PacketRecordMap {
56
m := make(PacketRecordMap)
61
// Merge the contents of srcKey into dstKey, modifying in-place.
62
// Packets in src not found in dst are appended to the matching parent.
63
// Conflicting packets and unmatched parents are ignored.
64
func MergeKey(dstKey *Pubkey, srcKey *Pubkey) {
65
dstObjects := MapKey(dstKey)
66
// Track source signable object in source traversal
67
var srcSignable PacketRecord
68
srcKey.Visit(func(srcObj PacketRecord) error {
69
// Match in destination tree
70
_, dstHas := dstObjects[GetUuid(srcObj)]
71
switch so := srcObj.(type) {
77
dstKey.subkeys = append(dstKey.subkeys, so)
82
dstKey.userIds = append(dstKey.userIds, so)
87
dstKey.userAttributes = append(dstKey.userAttributes, so)
90
dstParent, dstHasParent := dstObjects[GetUuid(srcSignable)]
91
dstSignable, isSignable := dstParent.(Signable)
92
if !dstHas && dstHasParent && isSignable {
93
dstSignable.AddSignature(so)
98
dstKey.updateDigests()