Exemple #1
0
/* expand -- expand a type abbreviation */
PUBLIC type expand(type t, frame f)
{
     def d = t->t_def;
     frame p = t->t_params;
     frame pp;
     int i;

     if (f == arid) {
	  /* Special case: parameters are already absolute */
	  pp = p;
     } else {
	  pp = mk_frame(d->d_nparams);
	  for (i = 0; i < d->d_nparams; i++)
	       pp->f_var[i] = seal(p->f_var[i], f);
     }

     if (d->d_kind == SCHEMA)
	  return seal(mk_sproduct(d->d_schema), pp);
     else {
	  type base;
	  if (! anal_power(seal(d->d_type, pp), &base, nil))
	       panic("expand");
	  return base;
     }
}
Exemple #2
0
bool ValidateSEAL()
{
	byte input[] = {0x37,0xa0,0x05,0x95,0x9b,0x84,0xc4,0x9c,0xa4,0xbe,0x1e,0x05,0x06,0x73,0x53,0x0f,0x5f,0xb0,0x97,0xfd,0xf6,0xa1,0x3f,0xbd,0x6c,0x2c,0xde,0xcd,0x81,0xfd,0xee,0x7c};
	byte output[32];
	byte key[] = {0x67, 0x45, 0x23, 0x01, 0xef, 0xcd, 0xab, 0x89, 0x98, 0xba, 0xdc, 0xfe, 0x10, 0x32, 0x54, 0x76, 0xc3, 0xd2, 0xe1, 0xf0};
	byte iv[] = {0x01, 0x35, 0x77, 0xaf};

	cout << "\nSEAL validation suite running...\n\n";

	SEAL<>::Encryption seal(key, sizeof(key), iv);
	unsigned int size = sizeof(input);
	bool pass = true;

	memset(output, 1, size);
	seal.ProcessString(output, input, size);
	for (unsigned int i=0; i<size; i++)
		if (output[i] != 0)
			pass = false;

	seal.Seek(1);
	output[1] = seal.ProcessByte(output[1]);
	seal.ProcessString(output+2, size-2);
	pass = pass && memcmp(output+1, input+1, size-1) == 0;

	cout << (pass ? "passed" : "FAILED") << endl;
	return pass;
}
Exemple #3
0
/* anal_power -- try to view a type as (P base) */
PUBLIC bool anal_power(type t, type *base, tree cxt)
{
     /* The common case (where t is simply a set type) accounts for a big
	fraction of the frames and type variables allocated if done by
	unification -- so it's just about worth doing directly. */

     frame f = arid;

     unpack(&t, &f, TRUE);
     switch (t->t_kind) {
     case POWERT:
	  *base = seal(t->t_base, f);
	  return TRUE;

     case TYPEVAR:
	  if (f == arid) return FALSE;
	  tv_val(t, f) = mk_power(*base = new_typevar(cxt));
	  return TRUE;

     default:
	  *base = err_type;
	  mark_error();
	  return (t == err_type);
     }
}
void	DecomposeTable<DCP_CABDOOR_BOARD_TYPE>::PostDecompose(soci::session& sql, soci::session& sqlInsert)
{
	DecomposeTable<DCP_CABDOOR_BOARD_SEAL_TYPE> seal(StatusInfo_, InfoSPtr_, JD_BoardSealInfo, VerCode_);
	seal.Decompose(sql,sqlInsert);

	DecomposeTable<DCP_CABDOOR_BOARD_GAP_TYPE> gap(StatusInfo_, InfoSPtr_, JD_BoardGapInfo, VerCode_);
	gap.Decompose(sql,sqlInsert);
}
Exemple #5
0
/* anal_rel_type -- View a type as P (dom x ran) */
PUBLIC bool anal_rel_type(type t, type *dom, type *ran, tree cxt)
{
     frame f = arid;

     unpack(&t, &f, TRUE);
     switch (t->t_kind) {
     case POWERT:
	  t = t->t_base;
	  unpack(&t, &f, TRUE);
	  switch (t->t_kind) {
	  case CPRODUCT: {
	       if (t->t_nfields != 2)
		    return FALSE;
	       *dom = seal(t->t_field[0], f);
	       *ran = seal(t->t_field[1], f);
	       return TRUE;
	  }

	  case TYPEVAR: 
	       if (f == arid)
		    return FALSE;
	       else {
		    frame ff = new_frame(2, cxt);
		    tv_val(t, f) = mk_binprod(*dom = tv_ref(0, ff),
					      *ran = tv_ref(1, ff));
		    return TRUE;
	       }
	   
	  default:
	       return FALSE;
	  }

     case TYPEVAR: 
	  if (f == arid)
	       return FALSE;
	  else {
	       frame ff = new_frame(2, cxt);
	       tv_val(t, f) = mk_power(mk_binprod(*dom = tv_ref(0, ff),
						  *ran = tv_ref(1, ff)));
	       return TRUE;
	  }

     default:
	  return FALSE;
     }
}
Exemple #6
0
message::message()
{
    _reader = nullptr;
    _writer = new binary_writer();

    memset(&_msg_header, 0, message_header::serialized_size());
    _msg_header.local_rpc_code = 0;
    seal(false, true);
}
Exemple #7
0
message::message()
{
    _reader = nullptr;
    _writer = new binary_writer();

    memset(&_msg_header, 0, MSG_HDR_SERIALIZED_SIZE);
    _msg_header.hdr_crc32 = _msg_header.body_crc32 = CRC_INVALID;
    _msg_header.local_rpc_code = 0;
    seal(false, true);
}
Exemple #8
0
/* anal_cproduct - test if a type is a product and get its components */
PUBLIC bool anal_cproduct(type t, type a[], int *n)
{
     frame f = arid;
     int i;

     unpack(&t, &f, TRUE);
     if (t->t_kind != CPRODUCT)
	  return FALSE;
     *n = t->t_nfields;
     for (i = 0; i < *n; i++)
	  a[i] = seal(t->t_field[i], f);
     return TRUE;
}
Exemple #9
0
/* ref_type -- find type of a reference */
PUBLIC type ref_type(sym x, tree p, env e, tree cxt)
{
     def d = find_def(x, e);
     frame f;

     if (d == NULL) {
#ifdef ASSUME
	  type t;
	  if (qflag && p == nil && (t = assume_type(x)) != NULL)
	       return t;
#endif

	  if (! partial_env(e)) {
	       tc_error(cxt->x_loc, "Identifier %n is not declared", x);
	       if (cxt->x_kind != REF)
		    tc_e_etc("Expression: %z", cxt);
	       tc_e_end();
	  }

	  return err_type;
     }

     f = new_frame(d->d_nparams, cxt);
     
     if (p != nil)
	  switch (d->d_kind) {
	  case GSET:
	  case VAR:
	       tc_error(cxt->x_loc, "%s %n cannot have parameters",
			d->d_kind == GSET ? "Basic type" : "Variable", x);
	       tc_e_etc("Expression: %z", cxt);
	       tc_e_end();
	       return err_type;

	  case GENCONST:
	       get_params("Generic constant", x, p, e, f, cxt->x_loc);
	       break;

	  default:
	       bad_tag("ref_type", d->d_kind);
	  }
	   
     if (! aflag && d->d_abbrev)
	  return mk_power(mk_abbrev(d, (p != nil ? f : alias(f))));
     else
	  return seal(d->d_type, f);
}
Exemple #10
0
File* Fs::create(const char *name, uint32_t size){
  toc_item_t ti;
  int id = -1;
  size_t file_cnt;

  osalDbgAssert(this->files_opened > 0, "FS not mounted");

  /* zero size forbidden */
  if (0 == size)
    return nullptr;

  file_cnt = get_file_cnt();

  /* check are we have spare slot for file */
  if (NVRAM_FS_MAX_FILE_CNT == file_cnt)
    return nullptr;

  id = find(name, &ti);
  if (-1 != id)
    return nullptr; /* such file already exists */

  /* check for name length */
  if (strlen(name) >= NVRAM_FS_MAX_FILE_NAME_LEN)
    return nullptr;

  /* there is no such file. Lets create it*/
  strncpy(ti.name, name, NVRAM_FS_MAX_FILE_NAME_LEN);
  ti.size = size;
  if (0 != file_cnt){
    toc_item_t tiprev;
    read_toc_item(&tiprev, file_cnt - 1);
    ti.start = tiprev.start + tiprev.size;
  }
  else
    ti.start = super.size + super.start;

  if ((ti.size + ti.start) > mtd.capacity())
    return nullptr;

  /* */
  write_toc_item(&ti, file_cnt);
  seal();
  return open(name);
}
Exemple #11
0
/* do_sref -- add the variables of a schema reference to an env */
PUBLIC void do_sref(tree t, env e, env v)
{
     tok dec = (tok) t->x_sref_decor;
     tree renames = t->x_sref_renames;
     def d;
     schema s;
     frame params;
     int i;

     if (t->x_kind != SREF) bad_tag("do_sref", t->x_kind);
     if (! open_sref(t, e, &d, &params)) {
	  v->e_partial = TRUE;
	  return;
     }
     s = d->d_schema;
     check_rename(d->d_schema, dec, renames, t);
     for (i = 0; i < s->z_ncomps; i++)
	  merge_def(VAR, get_rename(s->z_comp[i].z_name, dec, renames),
		    seal(s->z_comp[i].z_type, params), v, t, t->x_loc);
}
Exemple #12
0
/* comp_type -- get component type in a schema */
PUBLIC type comp_type(type t, sym x, tree cxt, int loc)
{
     type tt = t;
     frame f = arid;
     schema s;
     int i;

     unpack(&t, &f, TRUE);
     if (t->t_kind != SPRODUCT) panic("comp_type");
     s = t->t_schema;
     for (i = 0; i < s->z_ncomps; i++)
	  if (s->z_comp[i].z_name == x)
	       return seal(s->z_comp[i].z_type, f);

     tc_error(loc, "Selecting non-existent component %z", x);
     if (cxt != nil) {
	  tc_e_etc("Expression: %z", cxt);
	  tc_e_etc("Arg type:   %t", tt);
     }
     tc_e_end();
     mark_error();
     return err_type;
}
Exemple #13
0
/* Added call to refill ks_buf and reset counter and ks_pos. */
void seal_refill_buffer(seal_ctx *c)
{
    seal(c,c->counter,c->ks_buf);
    c->counter++;
    c->ks_pos = 0;
}
Exemple #14
0
/* tc_apply -- check a function application */
PRIVATE type tc_apply(int kind, tree t, tree fun, tree arg, env e)
{
     type actual = tc_expr(arg, e);
     type fun_type, formal, result;
     type formarg[MAX_ARGS], actarg[MAX_ARGS];
     int n_formals, n_actuals, i;
     frame param = arid;
     def d;
	            
     if (! aflag && fun->x_kind == REF 
	 && (d = find_def((sym) fun->x_tag, e)) != NULL
	 && d->d_tame && fun->x_params == nil)
	  /* A tame function */
	  fun_type = seal(d->d_type,
			  param = new_frame(d->d_nparams, fun));
     else
	  fun_type = tc_expr(fun, e);

     if (! anal_rel_type(fun_type, &formal, &result, fun)) {
	  if (fun_type != err_type) {
	       if (kind == APPLY)
		    tc_error(t->x_loc, "Application of a non-function");
	       else
		    tc_error(t->x_loc, "%s operator %n is not a function",
			     (kind == INOP ? "Infix" : "Postfix"),
			     fun->x_tag);
	       tc_e_etc("Expression: %z", t);
	       tc_e_etc("Found type: %t", fun_type);
	       tc_e_end();
	  }
	  mark_error();
	  return err_type;
     }

     if (arg->x_kind == TUPLE
	 && anal_cproduct(formal, formarg, &n_formals)) {
	  /* Special case: actual parameter is a tuple, and formal
	     parameter type is a cproduct. Check args one by one. */
	  if (! anal_cproduct(actual, actarg, &n_actuals))
	       panic("tc_apply");
	  if (n_actuals != n_formals) {
	       tc_error(t->x_loc, "Function expects %d arguments",
			n_formals);
	       tc_e_etc("Expression: %z", t);
	       tc_e_end();
	       mark_error();
	       return err_type;
	  }
	  for (i = 0; i < n_actuals; i++) {
	       if (param_unify(actarg[i], formarg[i], param))
		    continue;

	       if (kind == INOP)
		    tc_error(t->x_loc,
			     "%s argument of operator %n has wrong type",
			     (i == 0 ? "Left" : "Right"), fun->x_tag);
	       else
		    tc_error(t->x_loc, "Argument %d has wrong type", i+1);
	       tc_e_etc("Expression: %z", t);
	       tc_e_etc("Arg type:   %t", actarg[i]);
	       tc_e_etc("Expected:   %t", formarg[i]);
	       tc_e_end();
	  }
     }
     else if (! param_unify(actual, formal, param)) {
	  /* General case: check the single arg as a whole. */
	  tc_error(t->x_loc, "Argument of %s has wrong type",
		   (kind == POSTOP ? "postfix operator" : "application"));
	  tc_e_etc("Expression: %z", t);
	  tc_e_etc("Arg type:   %t", actual);
	  tc_e_etc("Expected:   %t", formal);
	  tc_e_end();
     }

     return result;
}
Exemple #15
0
PUBLIC type tc_expr(tree t, env e)
#endif
{
     switch (t->x_kind) {
     case REF:
	  return ref_type((sym) t->x_tag, t->x_params, e, t);
	  
     case INGEN:
	  return ref_type((sym) t->x_tag,
			  list2(t->x_param1, t->x_param2), e, t);

     case PREGEN:
	  return ref_type((sym) t->x_tag, list1(t->x_param), e, t);

     case NUMBER:
	  return nat_type;
	  
     case SEXPR: {
	  def d;
	  frame params;

	  if (! open_sref(t->x_ref, e, &d, &params))
	       return err_type;

	  if ((tok) t->x_ref->x_sref_decor != empty) {
	       tc_error(t->x_loc, "Decoration ignored in schema reference");
	       tc_e_etc("Expression: %z", t);
	       tc_e_end();
	  }

	  if (t->x_ref->x_sref_renames != nil) {
	       tc_error(t->x_loc, "Renaming ignored in schema reference");
	       tc_e_etc("Expression: %z", t);
	       tc_e_end();
	  }

	  if (! aflag && d->d_abbrev)
	       return mk_power(mk_abbrev(d, params));
	  else
	       return mk_power(seal(mk_sproduct(d->d_schema), params));
     }

     case POWER: {
	  type tt1, tt2;	  
	  if (! anal_power(tt1 = tc_expr(t->x_arg, e), &tt2, t->x_arg)) {
	       tc_error(t->x_loc, "Argument of \\power must be a set");
	       tc_e_etc("Expression: %z", t);
	       tc_e_etc("Arg type:   %t", tt1);
	       tc_e_end();
	  }
	  return mk_power(mk_power(tt2));
     }
	   
     case TUPLE : {
	  type a[MAX_ARGS];
	  int n = 0;
	  tree u;
	       
	  for (u = t->x_elements; u != nil; u = cdr(u)) {
	       if (n >= MAX_ARGS)
		    panic("tc_expr - tuple too big");
	       a[n++] = tc_expr(car(u), e);
	  }
	  return mk_cproduct(n, a);
     }

     case CROSS: {
	  type a[MAX_ARGS];
	  type tt1, tt2;
	  int n = 0;
	  tree u;

	  for (u = t->x_factors; u != nil; u = cdr(u)) {
	       if (n >= MAX_ARGS)
		    panic("tc_expr - product too big");
	       tt1 = tc_expr(car(u), e);
	       if (! anal_power(tt1, &tt2, car(u))) {
		    tc_error(t->x_loc,
			     "Argument %d of \\cross must be a set", n+1);
		    tc_e_etc("Expression: %z", t);
		    tc_e_etc("Arg %d type: %t", n+1, tt1);
		    tc_e_end();
	       }
	       a[n++] = tt2;
	  }
	  return mk_power(mk_cproduct(n, a));
     }

     case EXT:
     case SEQ:
     case BAG: {
	  type elem_type;
	  type tt;
	  tree u;

	  if (t->x_elements == nil)
	       elem_type = new_typevar(t);
	  else {
	       elem_type = tc_expr(car(t->x_elements), e);
	       for (u = cdr(t->x_elements); u != nil; u = cdr(u)) {
		    if (unify(elem_type, tt = tc_expr(car(u), e)))
			 elem_type = type_union(elem_type, arid, tt, arid);
		    else {
			 tc_error(t->x_loc, "Type mismatch in %s display",
				  (t->x_kind == EXT ? "set" :
				   t->x_kind == SEQ ? "sequence" : "bag"));
			 tc_e_etc("Expression: %z", car(u));
			 tc_e_etc("Has type:   %t", tt);
			 tc_e_etc("Expected:   %t", elem_type);
			 tc_e_end();
		    }
	       }
	  }
	  switch (t->x_kind) {
	  case EXT:
	       return mk_power(elem_type);
	  case SEQ:
	       return (aflag ? rel_type(num_type, elem_type) 
			     : mk_seq(elem_type));
	  case BAG:
	       return (aflag ? rel_type(elem_type, num_type) 
			     : mk_bag(elem_type));
	  }
     }

     case THETA: 
	  return theta_type(t, e, (type) NULL, t);

     case BINDING: {
	  tree u;
	  env e1 = new_env(e);
	  for (u = t->x_elements; u != nil; u = cdr(u))
	       add_def(VAR, (sym) car(u)->x_lhs, 
		       tc_expr(car(u)->x_rhs, e), e1);
	  return mk_sproduct(mk_schema(e1));
     }

     case SELECT: {
	  type a = tc_expr(t->x_arg, e);

	  if (type_kind(a) != SPRODUCT) {
	       tc_error(t->x_loc,
			"Argument of selection must have schema type");
	       tc_e_etc("Expression: %z", t);
	       tc_e_etc("Arg type:   %t", a);
	       tc_e_end();
	       mark_error();
	       return err_type;
	  }

	  switch (t->x_field->x_kind) {
	  case IDENT:
	       return (comp_type(a, (sym) t->x_field, t, t->x_loc));

	  case THETA:
	       return (theta_type(t->x_field, e, a, t));

	  default:
	       bad_tag("tc_expr.SELECT", t->x_field->x_kind);
	       return (type) NULL;
	  }
     }

     case APPLY:
	  return tc_apply(APPLY, t, t->x_arg1, t->x_arg2, e);

     case INOP:
	  return tc_apply(INOP, t, simply(t->x_op, t->x_loc), 
			  pair(t->x_rand1, t->x_rand2), e);

     case POSTOP:
	  return tc_apply(POSTOP, t, simply(t->x_op, t->x_loc), 
			  t->x_rand, e);

     case LAMBDA: {
	  env e1 = tc_schema(t->x_bvar, e);
	  type dom = tc_expr(char_tuple(t->x_bvar), e1);
	  type ran = tc_expr(t->x_body, e1);
	  return (aflag ? rel_type(dom, ran) : mk_pfun(dom, ran));
     }
    
     case COMP:
     case MU: {
	  env e1 = tc_schema(t->x_bvar, e);
	  type a = tc_expr(exists(t->x_body) ? the(t->x_body) :
			   char_tuple(t->x_bvar), e1);
	  return (t->x_kind == COMP ? mk_power(a) : a);
     }

     case LETEXPR:
	  return tc_expr(t->x_body, tc_letdefs(t->x_defs, e));

     case IF: {
	  type a, b;
	  tc_pred(t->x_if, e);
	  a = tc_expr(t->x_then, e);
	  b = tc_expr(t->x_else, e);
	  if (unify(a, b))
	       return type_union(a, arid, b, arid);
	  else {
	       tc_error(t->x_loc,
			"Type mismatch in conditional expression");
	       tc_e_etc("Expression: %z", t);
	       tc_e_etc("Then type:  %t", a);
	       tc_e_etc("Else type:  %t", b);
	       tc_e_end();
	       return err_type;
	  }
     }

     default:
	  bad_tag("tc_expr", t->x_kind);
	  /* dummy */ return (type) NULL;
     }
}