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_H_ |
| 6 | #define LIBUWEAVE_SRC_MACAROON_H_ |
| 7 | |
| 8 | #include <stdbool.h> |
| 9 | #include <stddef.h> |
| 10 | #include <stdint.h> |
| 11 | |
| 12 | #include "macaroon_caveat.h" |
| 13 | |
| 14 | #define UW_MACAROON_MAC_LEN 16 |
| 15 | |
| 16 | // Note: If we are looking to make memory savings on MCUs, |
| 17 | // at the cost of a little extra processing, we can make |
| 18 | // the macaroon encoding the actual in-memory representation. |
| 19 | // This can save much copying of macaroon data if need be. |
| 20 | typedef struct { |
| 21 | uint8_t mac_tag[UW_MACAROON_MAC_LEN]; |
| 22 | size_t num_caveats; |
| 23 | const UwMacaroonCaveat* caveats; |
| 24 | } UwMacaroon; |
| 25 | |
| 26 | bool uw_macaroon_new_from_mac_tag_(UwMacaroon* new_macaroon, |
| 27 | const uint8_t mac_tag[UW_MACAROON_MAC_LEN], |
| 28 | const UwMacaroonCaveat* caveats, |
| 29 | size_t num_caveats); |
| 30 | |
| 31 | bool uw_macaroon_new_from_root_key_(UwMacaroon* new_macaroon, |
| 32 | const uint8_t* root_key, |
| 33 | size_t root_key_len, |
| 34 | const UwMacaroonCaveat* caveats, |
| 35 | size_t num_caveats); |
| 36 | |
| 37 | bool uw_macaroon_verify_(const UwMacaroon* macaroon, |
| 38 | const uint8_t* root_key, |
| 39 | size_t root_key_len); |
| 40 | |
| 41 | // Create a new macaroon with a new caveat |
| 42 | bool uw_macaroon_extend_(const UwMacaroon* old_macaroon, |
| 43 | UwMacaroon* new_macaroon, |
| 44 | const UwMacaroonCaveat* additional_caveat, |
| 45 | uint8_t* buffer, size_t buffer_size); |
| 46 | |
Vitaly Buka | 6a8bd5d | 2015-12-08 21:06:59 -0800 | [diff] [blame] | 47 | // Encode a Macaroon to a byte string |
| 48 | bool uw_macaroon_dump_(const UwMacaroon* macaroon, |
| 49 | uint8_t* out, |
| 50 | size_t out_len, |
| 51 | size_t* resulting_str_len); |
| 52 | |
| 53 | // Decode a byte string to a Macaroon (the caveats_buffer here is used only for |
| 54 | // the caveat pointer list *caveats in the UwMacaroon *macaroon). One note is |
| 55 | // that the function doesn't copy string values to new buffers, so the caller |
| 56 | // may maintain the input string around to make caveats with string values to |
| 57 | // be usuable. |
| 58 | bool uw_macaroon_load_(const uint8_t* in, |
| 59 | size_t in_len, |
| 60 | uint8_t* caveats_buffer, |
| 61 | size_t caveats_buffer_size, |
| 62 | UwMacaroon* macaroon); |
| 63 | |
Vitaly Buka | 45dc9df | 2015-12-07 21:30:19 -0800 | [diff] [blame] | 64 | #endif // LIBUWEAVE_SRC_MACAROON_H_ |