Vitaly Buka | 45dc9df | 2015-12-07 21:30:19 -0800 | [diff] [blame] | 1 | // Copyright 2015 The Weave Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef LIBUWEAVE_SRC_MACAROON_CAVEAT_H_ |
| 6 | #define LIBUWEAVE_SRC_MACAROON_CAVEAT_H_ |
| 7 | |
| 8 | #include <stdbool.h> |
| 9 | #include <stddef.h> |
| 10 | #include <stdint.h> |
| 11 | |
| 12 | typedef struct { |
| 13 | size_t num_bytes; |
| 14 | const uint8_t* bytes; |
| 15 | } UwMacaroonCaveat; |
| 16 | |
| 17 | typedef enum { |
| 18 | kUwMacaroonCaveatTypeStop = 0, |
| 19 | kUwMacaroonCaveatTypeScope = 1, |
| 20 | kUwMacaroonCaveatTypeIdentifier = 2, |
| 21 | kUwMacaroonCaveatTypeIssued = 3, |
| 22 | kUwMacaroonCaveatTypeTTL = 4, |
| 23 | kUwMacaroonCaveatTypeExpiration = 5, |
| 24 | kUwMacaroonCaveatTypeSessionIdentifier = 16 |
| 25 | } UwMacaroonCaveatType; |
| 26 | |
Vitaly Buka | a37056e | 2015-12-09 14:53:39 -0800 | [diff] [blame^] | 27 | typedef enum { |
| 28 | kUwMacaroonCaveatScopeTypeOwner = 0, |
| 29 | kUwMacaroonCaveatScopeTypeManager = 1, |
| 30 | kUwMacaroonCaveatScopeTypeUser = 2, |
| 31 | kUwMacaroonCaveatScopeTypeViewer = 3, |
| 32 | } UwMacaroonCaveatScopeType; |
| 33 | |
Vitaly Buka | 45dc9df | 2015-12-07 21:30:19 -0800 | [diff] [blame] | 34 | bool uw_macaroon_caveat_create_without_value_(UwMacaroonCaveatType type, |
| 35 | uint8_t* buffer, |
| 36 | size_t buffer_size, |
| 37 | UwMacaroonCaveat* new_caveat); |
| 38 | bool uw_macaroon_caveat_create_with_uint_(UwMacaroonCaveatType type, |
| 39 | uint32_t value, uint8_t* buffer, |
| 40 | size_t buffer_size, |
| 41 | UwMacaroonCaveat* new_caveat); |
| 42 | bool uw_macaroon_caveat_create_with_str_(UwMacaroonCaveatType type, |
| 43 | const uint8_t* str, size_t str_len, |
| 44 | uint8_t* buffer, size_t buffer_size, |
| 45 | UwMacaroonCaveat* new_caveat); |
| 46 | |
| 47 | bool uw_macaroon_caveat_get_type_(const UwMacaroonCaveat* caveat, |
| 48 | UwMacaroonCaveatType* type); |
| 49 | bool uw_macaroon_caveat_get_value_uint_(const UwMacaroonCaveat* caveat, |
| 50 | uint32_t* unsigned_int); |
| 51 | bool uw_macaroon_caveat_get_value_str_(const UwMacaroonCaveat* caveat, |
| 52 | const uint8_t** str, size_t* str_len); |
| 53 | |
| 54 | bool uw_macaroon_caveat_sign_(const uint8_t* key, size_t key_len, |
| 55 | const UwMacaroonCaveat* caveat, uint8_t* mac_tag, |
| 56 | size_t mac_tag_size); |
| 57 | |
| 58 | #endif // LIBUWEAVE_SRC_MACAROON_CAVEAT_H_ |