示例#1
0
static int openssl_new_xattrs(lua_State*L)
{
  size_t i;
  int idx = 1;
  STACK_OF(X509_ATTRIBUTE) *attrs  = sk_X509_ATTRIBUTE_new_null();
  luaL_checktable(L, idx);

  for (i = 0; i < lua_rawlen(L, idx); i++)
  {
    X509_ATTRIBUTE* a = NULL;
    const char* eprefix = NULL;
    lua_rawgeti(L, idx, i + 1);
    if (!lua_istable(L, -1))
    {
      lua_pushfstring(L, "value at %d is not table", i + 1);
      luaL_argerror(L, idx, lua_tostring(L, -1));
    }
    lua_pushfstring(L, "table %d at argument #%d:", idx, i + 1);
    eprefix = lua_tostring(L, -1);
    lua_pop(L, 1);

    a = openssl_new_xattribute(L, &a, lua_gettop(L), eprefix);
    if (a)
    {
      sk_X509_ATTRIBUTE_push(attrs, a);
    }
    lua_pop(L, 1);
  }
  PUSH_OBJECT(attrs, "openssl.stack_of_x509_attribute");
  return 1;
}
示例#2
0
/***
add attribute to x509_req object
@function attribute
@tparam x509_attribute attribute attribute to add
@treturn boolean result
*/
static LUA_FUNCTION(openssl_csr_attribute)
{
  X509_REQ *csr = CHECK_OBJECT(1, X509_REQ, "openssl.x509_req");
  if (auxiliar_getclassudata(L, "openssl.x509_attribute", 2))
  {
    X509_ATTRIBUTE *attr = CHECK_OBJECT(2, X509_ATTRIBUTE, "openssl.x509_attribute");
    int ret = X509_REQ_add1_attr(csr, attr);
    return openssl_pushresult(L, ret);
  }
  else if (lua_isnumber(L, 2))
  {
    int loc = luaL_checkint(L, 2);
    X509_ATTRIBUTE *attr = NULL;
    if (lua_isnone(L, 3))
    {
      attr = X509_REQ_get_attr(csr, loc);
      attr = X509_ATTRIBUTE_dup(attr);
    }
    else if (lua_isnil(L, 3))
    {
      attr = X509_REQ_delete_attr(csr, loc);
    }
    if (attr)
    {
      PUSH_OBJECT(attr, "openssl.x509_attribute");
    }
    else
      lua_pushnil(L);
    return 1;
  }
  else if (lua_istable(L, 2))
  {
    int i;
    int ret = 1;
    int n = lua_rawlen(L, 2);
    for (i = 1; ret == 1 && i <= n; i++)
    {
      X509_ATTRIBUTE *attr;
      lua_rawgeti(L, 2, i);
      attr = NULL;
      if (lua_istable(L, -1))
      {
        attr = openssl_new_xattribute(L, &attr, -1, NULL);
        ret = X509_REQ_add1_attr(csr, attr);
        X509_ATTRIBUTE_free(attr);
      }
      else
      {
        attr = CHECK_OBJECT(-1, X509_ATTRIBUTE, "openssl.x509_attribute");
        ret = X509_REQ_add1_attr(csr, attr);
      }
      lua_pop(L, 1);
    }
    openssl_pushresult(L, ret);
    return 1;
  }

  return 0;
}
示例#3
0
static int openssl_xattr_new(lua_State*L)
{
  X509_ATTRIBUTE *x = NULL;
  luaL_checktable(L, 1);

  x = openssl_new_xattribute(L, &x, 1, NULL);
  PUSH_OBJECT(x, "openssl.x509_attribute");
  return 1;
}
示例#4
0
文件: xattrs.c 项目: Udo/lua-openssl
static int openssl_xattr_new(lua_State*L) {
  X509_ATTRIBUTE *x=NULL;
  int utf8;
  luaL_checktable(L,1);
  utf8 = lua_isnoneornil(L, 2) ? 1 : lua_toboolean(L, 2);

  x = openssl_new_xattribute(L, &x, 1, utf8);
  PUSH_OBJECT(x,"openssl.x509_attribute");
  return 1;
}
示例#5
0
文件: xattrs.c 项目: Udo/lua-openssl
static int openssl_new_xattrs(lua_State*L)
{
  size_t i;
  int idx = 1;
  int utf8 = lua_isnoneornil(L, 2) ? 1 : lua_toboolean(L, 2);
  STACK_OF(X509_ATTRIBUTE) *attrs  = sk_X509_ATTRIBUTE_new_null();
  luaL_checktable(L, idx);

  for(i=0; i<lua_rawlen(L, idx); i++)
  {
    X509_ATTRIBUTE* a = NULL;
    lua_rawgeti(L, idx, i+1);
    a = openssl_new_xattribute(L, &a, -1,utf8);
    if(a) {
      sk_X509_ATTRIBUTE_push(attrs,a);
    }
    lua_pop(L,1);
  }
  PUSH_OBJECT(attrs, "openssl.stack_of_x509_attribute");
  return 1;
}