Open a resumption ticket. Returns the recovered ticket plaintext, or an error on any failure (the caller MUST silently drop the query).
(tk: &TicketKey, ticket: &[u8])
| 262 | /// Open a resumption ticket. Returns the recovered ticket plaintext, or an |
| 263 | /// error on any failure (the caller MUST silently drop the query). |
| 264 | pub fn open_ticket(tk: &TicketKey, ticket: &[u8]) -> Result<Vec<u8>, Error> { |
| 265 | ensure!( |
| 266 | ticket.len() > TICKET_KEY_ID_SIZE + TICKET_NONCE_SIZE + MAC_SIZE, |
| 267 | "Short ticket" |
| 268 | ); |
| 269 | ensure!(ticket[0..TICKET_KEY_ID_SIZE] == tk.id, "Unknown ticket key"); |
| 270 | let nonce = &ticket[TICKET_KEY_ID_SIZE..TICKET_KEY_ID_SIZE + TICKET_NONCE_SIZE]; |
| 271 | let sealed = &ticket[TICKET_KEY_ID_SIZE + TICKET_NONCE_SIZE..]; |
| 272 | tk.key.open_raw(nonce, sealed) |
| 273 | } |
| 274 | |
| 275 | /// Build the response control block that carries a freshly issued ticket. |
| 276 | pub fn control_block(ticket_lifetime: u32, ticket: &[u8]) -> Vec<u8> { |