forked from ProtonMail/go-proton-api
-
Notifications
You must be signed in to change notification settings - Fork 4
/
calendar_event_types.go
110 lines (87 loc) · 2.23 KB
/
calendar_event_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package proton
import (
"encoding/base64"
"github.com/ProtonMail/gopenpgp/v2/crypto"
)
type CalendarEvent struct {
ID string
UID string
CalendarID string
SharedEventID string
CreateTime int64
LastEditTime int64
StartTime int64
StartTimezone string
EndTime int64
EndTimezone string
FullDay Bool
Author string
Permissions CalendarPermissions
Attendees []CalendarAttendee
SharedKeyPacket string
CalendarKeyPacket string
SharedEvents []CalendarEventPart
CalendarEvents []CalendarEventPart
AttendeesEvents []CalendarEventPart
PersonalEvents []CalendarEventPart
}
// TODO: Only personal events have MemberID; should we have a different type for that?
type CalendarEventPart struct {
MemberID string
Type CalendarEventType
Data string
Signature string
Author string
}
func (part CalendarEventPart) Decode(calKR *crypto.KeyRing, addrKR *crypto.KeyRing, kp []byte) error {
if part.Type&CalendarEventTypeEncrypted != 0 {
var enc *crypto.PGPMessage
if kp != nil {
raw, err := base64.StdEncoding.DecodeString(part.Data)
if err != nil {
return err
}
enc = crypto.NewPGPSplitMessage(kp, raw).GetPGPMessage()
} else {
var err error
if enc, err = crypto.NewPGPMessageFromArmored(part.Data); err != nil {
return err
}
}
dec, err := calKR.Decrypt(enc, nil, crypto.GetUnixTime())
if err != nil {
return err
}
part.Data = dec.GetString()
}
if part.Type&CalendarEventTypeSigned != 0 {
sig, err := crypto.NewPGPSignatureFromArmored(part.Signature)
if err != nil {
return err
}
if err := addrKR.VerifyDetached(crypto.NewPlainMessageFromString(part.Data), sig, crypto.GetUnixTime()); err != nil {
return err
}
}
return nil
}
type CalendarEventType int
const (
CalendarEventTypeClear CalendarEventType = iota
CalendarEventTypeEncrypted
CalendarEventTypeSigned
)
type CalendarAttendee struct {
ID string
Token string
Status CalendarAttendeeStatus
Permissions CalendarPermissions
}
// TODO: What is this?
type CalendarAttendeeStatus int
const (
CalendarAttendeeStatusPending CalendarAttendeeStatus = iota
CalendarAttendeeStatusMaybe
CalendarAttendeeStatusNo
CalendarAttendeeStatusYes
)