mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
federation/pdu: add AddSignature helper method
This commit is contained in:
parent
dd51c562ab
commit
36c353abc7
2 changed files with 14 additions and 7 deletions
|
|
@ -123,6 +123,19 @@ func (pdu *PDU) ToClientEvent(roomVersion id.RoomVersion) (*event.Event, error)
|
|||
return evt, nil
|
||||
}
|
||||
|
||||
func (pdu *PDU) AddSignature(serverName string, keyID id.KeyID, signature string) {
|
||||
if signature == "" {
|
||||
return
|
||||
}
|
||||
if pdu.Signatures == nil {
|
||||
pdu.Signatures = make(map[string]map[id.KeyID]string)
|
||||
}
|
||||
if _, ok := pdu.Signatures[serverName]; !ok {
|
||||
pdu.Signatures[serverName] = make(map[id.KeyID]string)
|
||||
}
|
||||
pdu.Signatures[serverName][keyID] = signature
|
||||
}
|
||||
|
||||
func marshalCanonical(data any) (jsontext.Value, error) {
|
||||
marshaledBytes, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -28,13 +28,7 @@ func (pdu *PDU) Sign(roomVersion id.RoomVersion, serverName string, keyID id.Key
|
|||
return fmt.Errorf("failed to marshal redacted PDU to sign: %w", err)
|
||||
}
|
||||
signature := ed25519.Sign(privateKey, rawJSON)
|
||||
if pdu.Signatures == nil {
|
||||
pdu.Signatures = make(map[string]map[id.KeyID]string)
|
||||
}
|
||||
if _, ok := pdu.Signatures[serverName]; !ok {
|
||||
pdu.Signatures[serverName] = make(map[id.KeyID]string)
|
||||
}
|
||||
pdu.Signatures[serverName][keyID] = base64.RawStdEncoding.EncodeToString(signature)
|
||||
pdu.AddSignature(serverName, keyID, base64.RawStdEncoding.EncodeToString(signature))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue