# Struct crypto::voice::GroupKeys

> A participant's key state for one voice session.

`zaun_community_protocol::crypto::voice::GroupKeys` · Struct

```rust
pub struct GroupKeys { … }
```

A participant's key state for one voice session.

## Methods

### `new`

```rust
pub fn new(member_key: &SecretKey, community_id: CommunityId, channel_id: ChannelId, member_id: MemberId, min_suite: u8, created_at: u64) -> Result<Self, VoiceError>
```

Starts a voice session: a fresh voice session id and X-Wing key pair, and the key
package signed by `member_key`.

# Errors
`VoiceError::Rng` or `VoiceError::Signed`.

### `voice_session`

```rust
pub const fn voice_session(&self) -> VoiceSessionId
```

This participant's voice session.

### `key_package`

```rust
pub const fn key_package(&self) -> &SignedKeyPackage
```

This participant's signed key package (send its `SignedKeyPackage::to_wire`).

### `needs_rekey`

```rust
pub const fn needs_rekey(&self) -> bool
```

Whether the peer set changed since the last `Self::rekey`.

### `peers`

```rust
pub fn peers(&self) -> impl Iterator<Item = (VoiceSessionId, MemberId)> + '_
```

The voice sessions of the current peers.

### `add_peer`

```rust
pub fn add_peer(&mut self, member_id: MemberId, member_key: &PublicKey, package_wire: &[u8]) -> Result<VoiceSessionId, VoiceError>
```

Verifies and adds a peer's key package. `member_key` is the roster's key for
`member_id`. Re-adding the same package is a no-op.

# Errors
As `KeyPackage::verify`; `VoiceError::Recipients` beyond `MAX_RECIPIENTS` peers;
`VoiceError::KidCollision` when its KID tag equals another participant's (the newer
participant rejoins with a new voice session); `VoiceError::Mismatch` for a different
package under a known session.

### `remove_peer`

```rust
pub fn remove_peer(&mut self, session: &VoiceSessionId) -> bool
```

Forgets a peer and its keys. Returns whether it was known.

### `rekey`

```rust
pub fn rekey(&mut self, member_key: &SecretKey, created_at: u64) -> Result<Rekey, VoiceError>
```

Makes the next epoch: a fresh base key wrapped to every current peer and the signed
sender-keys message. The new key seals only after `Self::activate`.

# Errors
`VoiceError::Exhausted` after 2^32 epochs; `VoiceError::Rng`; HPKE or signing
failures.

### `activate`

```rust
pub fn activate(&mut self) -> bool
```

Switches sealing to the newest epoch. Returns whether there was one waiting.

### `seal`

```rust
pub fn seal(&mut self, metadata: &[u8], frame: &[u8]) -> Result<Vec<u8>, VoiceError>
```

Seals one of this participant's frames under the active epoch.

# Errors
`VoiceError::NoSenderKey` before the first activation; `VoiceError::Exhausted`.

### `accept_sender_keys`

```rust
pub fn accept_sender_keys(&mut self, from: &VoiceSessionId, sender_keys_wire: &[u8], wrapped: &[u8]) -> Result<u32, VoiceError>
```

Installs a peer's epoch key: verifies the sender-keys message under the peer's member
key, checks that `wrapped` is the key it signed for this participant, opens it, and
keeps the peer's previous epoch for frames still in flight.

# Errors
`VoiceError::UnknownPeer`, verification errors, `VoiceError::NotARecipient`,
`VoiceError::WrappedHash`, `VoiceError::StaleEpoch` or `VoiceError::Unwrap`.

### `open`

```rust
pub fn open(&mut self, metadata: &[u8], frame: &[u8]) -> Result<(VoiceSessionId, Vec<u8>), VoiceError>
```

Opens a frame from whichever peer's KID it carries.

# Errors
`VoiceError::Header`, `VoiceError::UnknownKid`, `VoiceError::Replay` or
`VoiceError::Open`.

### `open_from`

```rust
pub fn open_from(&mut self, from: &VoiceSessionId, metadata: &[u8], frame: &[u8]) -> Result<Vec<u8>, VoiceError>
```

Opens a frame that the transport says came from `from`; another peer's KID is refused.

# Errors
As `Self::open`, and `VoiceError::UnknownPeer`.

## Trait implementations

`Debug`

[Full rustdoc page](/docs/api/rust/zaun-community-protocol/zaun_community_protocol/crypto/voice/group/struct.GroupKeys.html)
