blob: 78373c87a35dcdc15e7b09386d1bece57f3da967 [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_CAVEAT_H_
6#define LIBUWEAVE_SRC_MACAROON_CAVEAT_H_
7
8#include <stdbool.h>
9#include <stddef.h>
10#include <stdint.h>
11
12typedef struct {
13 size_t num_bytes;
14 const uint8_t* bytes;
15} UwMacaroonCaveat;
16
17typedef 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 Bukaa37056e2015-12-09 14:53:39 -080027typedef enum {
28 kUwMacaroonCaveatScopeTypeOwner = 0,
29 kUwMacaroonCaveatScopeTypeManager = 1,
30 kUwMacaroonCaveatScopeTypeUser = 2,
31 kUwMacaroonCaveatScopeTypeViewer = 3,
32} UwMacaroonCaveatScopeType;
33
Vitaly Buka45dc9df2015-12-07 21:30:19 -080034bool uw_macaroon_caveat_create_without_value_(UwMacaroonCaveatType type,
35 uint8_t* buffer,
36 size_t buffer_size,
37 UwMacaroonCaveat* new_caveat);
38bool uw_macaroon_caveat_create_with_uint_(UwMacaroonCaveatType type,
39 uint32_t value, uint8_t* buffer,
40 size_t buffer_size,
41 UwMacaroonCaveat* new_caveat);
42bool 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
47bool uw_macaroon_caveat_get_type_(const UwMacaroonCaveat* caveat,
48 UwMacaroonCaveatType* type);
49bool uw_macaroon_caveat_get_value_uint_(const UwMacaroonCaveat* caveat,
50 uint32_t* unsigned_int);
51bool uw_macaroon_caveat_get_value_str_(const UwMacaroonCaveat* caveat,
52 const uint8_t** str, size_t* str_len);
53
54bool 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_