# Calendar

## Calendar

Calendar and calendar event retrieval via `/calendar/v1`. Includes key management for encrypted calendar data.

## Operations

### Calendars

```go
// List all calendars
calendars, err := c.GetCalendars(ctx)

// Get a single calendar
cal, err := c.GetCalendar(ctx, calendarID)

// Get encryption keys for a calendar
keys, err := c.GetCalendarKeys(ctx, calendarID)

// Get shared calendar members
members, err := c.GetCalendarMembers(ctx, calendarID)

// Get passphrase for calendar key decryption
passphrase, err := c.GetCalendarPassphrase(ctx, calendarID)
```

### Calendar Events

```go
// Count events
count, err := c.CountCalendarEvents(ctx, calendarID)

// Paginated listing with optional filters
events, err := c.GetCalendarEvents(ctx, calendarID, page, pageSize, filter)

// Auto-paginating - get all events
allEvents, err := c.GetAllCalendarEvents(ctx, calendarID, filter)

// Single event by ID
event, err := c.GetCalendarEvent(ctx, calendarID, eventID)
```

## Decryption

Calendar events use **two-layer encryption**:

1. Calendar keys (passphrase-locked)
2. Shared events add a second layer of sharing key packets

```go
// Unlock calendar keys with passphrase
keyRing, err := keys.Unlock(passphrase)

// Decrypt individual event parts
decoded, err := eventPart.Decode(calKR, addrKR, keyPacket)
// Handles both two-layer decryption and PGP signature verification
```

## Key Types

| Type | Description |
|---|---|
| `Calendar` | ID, name, description, color, display flag, type (normal/subscribed), flags |
| `CalendarKey` | Encrypted private key with `Unlock(passphrase)` returning `*crypto.Key` |
| `CalendarKeys` | Slice of keys with `Unlock(passphrase)` returning `*crypto.KeyRing` |
| `CalendarMember` | ID, permissions, email, color, display, calendarID |
| `CalendarPassphrase` | Encrypted passphrase with `Decrypt(memberID, addrKR)` for decryption |
| `CalendarEvent` | UID, start/end times, timezone, full-day flag, author, attendees, encrypted parts |
| `CalendarEventPart` | Individual part with type (clear/encrypted/signed), data, signature, author |
| `EventAction` | Delete, Create, Update, UpdateFlags |

## PGP Signature Verification

Encrypted calendar parts can also be signed. The `Decode` method verifies signatures using the address keyring.