Computer Laboratory

tesla_key.c File Reference
#include "tesla_internal.h"
#include <inttypes.h>
#include <stdio.h>
+ Include dependency graph for tesla_key.c:

Go to the source code of this file.

Macros

#define IS_SET(mask, index)   (mask & (1 << index))
 

Functions

int tesla_key_matches (const struct tesla_key *pattern, const struct tesla_key *k)
 Check to see if a key matches a pattern. More...
 
int32_t tesla_key_union (tesla_key *dest, const tesla_key *source)
 

Macro Definition Documentation

#define IS_SET (   mask,
  index 
)    (mask & (1 << index))

Definition at line 41 of file tesla_key.c.

Referenced by tesla_key_union().

Function Documentation

int32_t tesla_key_union ( tesla_key dest,
const tesla_key source 
)

Definition at line 69 of file tesla_key.c.

References IS_SET, TESLA_ERROR_EINVAL, TESLA_KEY_SIZE, TESLA_SUCCESS, tesla_key::tk_keys, and tesla_key::tk_mask.

70 {
71  for (uint32_t i = 0; i < TESLA_KEY_SIZE; i++) {
72  if (IS_SET(source->tk_mask, i)) {
73  if (IS_SET(dest->tk_mask, i)) {
74  if (dest->tk_keys[i] != source->tk_keys[i])
75  return (TESLA_ERROR_EINVAL);
76  } else {
77  dest->tk_keys[i] = source->tk_keys[i];
78  }
79  }
80  }
81 
82  dest->tk_mask |= source->tk_mask;
83  return (TESLA_SUCCESS);
84 }