hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

types.ha (3916B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use errors;
      5 use types::c;
      6 
      7 // A key ID.
      8 export type serial = i32;
      9 
     10 // Returned when a desired key was not found.
     11 export type nokey = !void;
     12 
     13 // A tagged union of all possible error types.
     14 export type error = !(nokey | errors::error);
     15 
     16 // The caller's thread-specific keyring.
     17 export def THREAD_KEYRING: serial = -1;
     18 
     19 // The caller's process-specific keyring.
     20 export def PROCESS_KEYRING: serial = -2;
     21 
     22 // The caller's session-specific keyring.
     23 export def SESSION_KEYRING: serial = -3;
     24 
     25 // The caller's UID-specific keyring.
     26 export def USER_KEYRING: serial = -4;
     27 
     28 // The caller's UID-session keyring.
     29 export def USER_SESSION_KEYRING: serial = -5;
     30 
     31 // The caller's GID-specific keyring.
     32 export def GROUP_KEYRING: serial = -6;
     33 
     34 // The caller's GID-session keyring.
     35 export def REQKEY_AUTH_KEY: serial = -7;
     36 
     37 // The Key ID for the [[reqkey]] destination keyring.
     38 export def REQUESTOR_KEYRING: serial = -8;
     39 
     40 // request-key default keyrings
     41 export type reqkey = enum int {
     42 	NO_CHANGE = -1,
     43 	DEFAULT = 0,
     44 	THREAD_KEYRING = 1,
     45 	PROCESS_KEYRING = 2,
     46 	SESSION_KEYRING = 3,
     47 	USER_KEYRING = 4,
     48 	USER_SESSION_KEYRING = 5,
     49 	GROUP_KEYRING = 6,
     50 	REQUESTOR_KEYRING = 7,
     51 };
     52 
     53 // keyctl commands
     54 export type command = enum int {
     55 	GET_KEYRING_ID = 0,
     56 	JOIN_SESSION_KEYRING = 1,
     57 	UPDATE = 2,
     58 	REVOKE = 3,
     59 	CHOWN = 4,
     60 	SETPERM = 5,
     61 	DESCRIBE = 6,
     62 	CLEAR = 7,
     63 	LINK = 8,
     64 	UNLINK = 9,
     65 	SEARCH = 10,
     66 	READ = 11,
     67 	INSTANTIATE = 12,
     68 	NEGATE = 13,
     69 	SET_REQKEY_KEYRING = 14,
     70 	SET_TIMEOUT = 15,
     71 	ASSUME_AUTHORITY = 16,
     72 	GET_SECURITY = 17,
     73 	SESSION_TO_PARENT = 18,
     74 	REJECT = 19,
     75 	INSTANTIATE_IOV = 20,
     76 	INVALIDATE = 21,
     77 	GET_PERSISTENT = 22,
     78 	DH_COMPUTE = 23,
     79 	PKEY_QUERY = 24,
     80 	PKEY_ENCRYPT = 25,
     81 	PKEY_DECRYPT = 26,
     82 	PKEY_SIGN = 27,
     83 	PKEY_VERIFY = 28,
     84 	RESTRICT_KEYRING = 29,
     85 	MOVE = 30,
     86 	CAPABILITIES = 31,
     87 	WATCH_KEY = 32,
     88 };
     89 
     90 // Input for [[command::DH_COMPUTE]]
     91 export type dh_params = struct {
     92 	private: i32,
     93 	prime: i32,
     94 	base: i32,
     95 };
     96 
     97 // Output for [[command::DH_COMPUTE]]
     98 export type kdf_params = struct {
     99 	hashname: *c::char,
    100 	otherinfo: *c::char,
    101 	otherinfolen: u32,
    102 	__spare: [8]u32,
    103 };
    104 
    105 export type support = enum u32 {
    106 	SUPPORTS_ENCRYPT = 0x01,
    107 	SUPPORTS_DECRYPT = 0x02,
    108 	SUPPORTS_SIGN = 0x04,
    109 	SUPPORTS_VERIFY = 0x08,
    110 };
    111 
    112 export type pkey_query = struct {
    113 	supported_ops: u32,
    114 	key_size: u32,
    115 	max_data_size: u16,
    116 	max_sig_size: u16,
    117 	max_enc_size: u16,
    118 	max_dec_size: u16,
    119 	__spare: [10]u32,
    120 };
    121 
    122 export type pkey_params = struct {
    123 	key_id: i32,
    124 	in_len: u32,
    125 	union {
    126 		out_len: u32,
    127 		in2_len: u32,
    128 	},
    129 	__spare: [7]u32,
    130 };
    131 
    132 export type caps = enum u8 {
    133 	CAPS0_CAPABILITIES = 0x01,
    134 	CAPS0_PERSISTENT_KEYRINGS = 0x02,
    135 	CAPS0_DIFFIE_HELLMAN = 0x04,
    136 	CAPS0_PUBLIC_KEY = 0x08,
    137 	CAPS0_BIG_KEY = 0x10,
    138 	CAPS0_INVALIDATE = 0x20,
    139 	CAPS0_RESTRICT_KEYRING = 0x40,
    140 	CAPS0_MOVE = 0x80,
    141 	CAPS1_NS_KEYRING_NAME = 0x01,
    142 	CAPS1_NS_KEY_TAG = 0x02,
    143 	CAPS1_NOTIFICATIONS = 0x04,
    144 };
    145 
    146 export type perm = enum u32 {
    147 	KEY_OTH_VIEW = 0x01,
    148 	KEY_OTH_READ = 0x02,
    149 	KEY_OTH_WRITE = 0x04,
    150 	KEY_OTH_SEARCH = 0x08,
    151 	KEY_OTH_LINK = 0x10,
    152 	KEY_OTH_SETATTR = 0x20,
    153 	KEY_OTH_ALL = 0x3f,
    154 
    155 	KEY_GRP_VIEW = 0x0100,
    156 	KEY_GRP_READ = 0x0200,
    157 	KEY_GRP_WRITE = 0x0400,
    158 	KEY_GRP_SEARCH = 0x0800,
    159 	KEY_GRP_LINK = 0x1000,
    160 	KEY_GRP_SETATTR = 0x2000,
    161 	KEY_GRP_ALL = 0x3f00,
    162 
    163 	KEY_USR_VIEW = 0x010000,
    164 	KEY_USR_READ = 0x020000,
    165 	KEY_USR_WRITE = 0x040000,
    166 	KEY_USR_SEARCH = 0x080000,
    167 	KEY_USR_LINK = 0x100000,
    168 	KEY_USR_SETATTR = 0x200000,
    169 	KEY_USR_ALL = 0x3f0000,
    170 
    171 	KEY_POS_VIEW = 0x01000000,
    172 	KEY_POS_READ = 0x02000000,
    173 	KEY_POS_WRITE = 0x04000000,
    174 	KEY_POS_SEARCH = 0x08000000,
    175 	KEY_POS_LINK = 0x10000000,
    176 	KEY_POS_SETATTR = 0x20000000,
    177 	KEY_POS_ALL = 0x3f000000,
    178 };
    179 
    180 // Converts an [[error]] into a human-friendly string.
    181 export fn strerror(err: error) const str = match (err) {
    182 case nokey =>
    183 	return "A desired key was not found";
    184 case let err: errors::error =>
    185 	return errors::strerror(err);
    186 };