blob: 61242f736d830635c88b0c9b64004c8cebb5387d [file] [log] [blame]
Vitaly Buka45dc9df2015-12-07 21:30:19 -08001// 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.
20typedef struct {
21 uint8_t mac_tag[UW_MACAROON_MAC_LEN];
22 size_t num_caveats;
23 const UwMacaroonCaveat* caveats;
24} UwMacaroon;
25
26bool 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
31bool 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
37bool 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
42bool 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 Buka6a8bd5d2015-12-08 21:06:59 -080047// Encode a Macaroon to a byte string
48bool 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.
58bool 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 Buka45dc9df2015-12-07 21:30:19 -080064#endif // LIBUWEAVE_SRC_MACAROON_H_