本文整理汇总了C++中ASN1_object_size函数的典型用法代码示例。如果您正苦于以下问题:C++ ASN1_object_size函数的具体用法?C++ ASN1_object_size怎么用?C++ ASN1_object_size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ASN1_object_size函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: i2d_X509_EXTENSION
int i2d_X509_EXTENSION(X509_EXTENSION *a, unsigned char **pp)
{
int k=0;
int r=0,ret=0;
unsigned char **p=NULL;
if (a == NULL) return(0);
p=NULL;
for (;;)
{
if (k)
{
r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE);
if (pp == NULL) return(r);
p=pp;
ASN1_put_object(p,1,ret,V_ASN1_SEQUENCE,
V_ASN1_UNIVERSAL);
}
ret+=i2d_ASN1_OBJECT(a->object,p);
if ((a->critical) || a->netscape_hack)
ret+=i2d_ASN1_BOOLEAN(a->critical,p);
ret+=i2d_ASN1_OCTET_STRING(a->value,p);
if (k++) return(r);
}
}
示例2: i2d_X509_ATTRIBUTE
/* sequence */
int i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a, unsigned char **pp)
{
int k=0;
int r=0,ret=0;
unsigned char **p=NULL;
if (a == NULL) return(0);
p=NULL;
for (;;)
{
if (k)
{
r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE);
if (pp == NULL) return(r);
p=pp;
ASN1_put_object(p,1,ret,V_ASN1_SEQUENCE,
V_ASN1_UNIVERSAL);
}
ret+=i2d_ASN1_OBJECT(a->object,p);
if (a->set)
ret+=i2d_ASN1_SET_OF_ASN1_TYPE(a->value.set,p,(i2d_func_t)i2d_ASN1_TYPE,
V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
else
ret+=i2d_ASN1_TYPE(a->value.single,p);
if (k++) return(r);
}
}
示例3: btls_change_obj_data
int btls_change_obj_data(ASN1_OBJECT **a, const char* pp)
{
int res = 1;
unsigned char *buf;
unsigned char *p;
const unsigned char *cp;
int i, j;
i=a2d_ASN1_OBJECT(NULL,0, pp,-1);
if (i <= 0) {
/* Don't clear the error */
/*ERR_clear_error();*/
return 0;
}
/* Work out total size */
j = ASN1_object_size(0,i,V_ASN1_OBJECT);
if((buf=(unsigned char *)OPENSSL_malloc(j)) == NULL) return 0;
p = buf;
/* Write out tag+length */
ASN1_put_object(&p,0,i,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
/* Write out contents */
a2d_ASN1_OBJECT(p,i,pp,-1);
cp=buf;
(*a)=btls_d2i_ASN1_OBJECT(a,&cp,j);
OPENSSL_free(buf);
return 1;
}
示例4: i2d_ASN1_bytes
int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
{
int ret,r,constructed;
unsigned char *p;
if (a == NULL) return(0);
if (tag == V_ASN1_BIT_STRING)
return(i2d_ASN1_BIT_STRING(a,pp));
ret=a->length;
r=ASN1_object_size(0,ret,tag);
if (pp == NULL) return(r);
p= *pp;
if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET))
constructed=1;
else
constructed=0;
ASN1_put_object(&p,constructed,ret,tag,xclass);
memcpy(p,a->data,a->length);
p+=a->length;
*pp= p;
return(r);
}
示例5: ECDSA_size
int ECDSA_size(const EC_KEY *r)
{
int ret,i;
ASN1_INTEGER bs;
BIGNUM *order=NULL;
unsigned char buf[4];
const EC_GROUP *group;
if (r == NULL)
return 0;
group = EC_KEY_get0_group(r);
if (group == NULL)
return 0;
if ((order = BN_new()) == NULL) return 0;
if (!EC_GROUP_get_order(group,order,NULL))
{
BN_clear_free(order);
return 0;
}
i=BN_num_bits(order);
bs.length=(i+7)/8;
bs.data=buf;
bs.type=V_ASN1_INTEGER;
/* If the top bit is set the asn1 encoding is 1 larger. */
buf[0]=0xff;
i=i2d_ASN1_INTEGER(&bs,NULL);
i+=i; /* r and s */
ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
BN_clear_free(order);
return(ret);
}
示例6: ossl_asn1prim_to_der
static VALUE
ossl_asn1prim_to_der(VALUE self, SEL sel)
{
ASN1_TYPE *asn1;
int tn, tc, explicit;
long len, reallen;
unsigned char *buf, *p;
VALUE str;
tn = NUM2INT(ossl_asn1_get_tag(self));
tc = ossl_asn1_tag_class(self);
explicit = ossl_asn1_is_explicit(self);
asn1 = ossl_asn1_get_asn1type(self);
len = ASN1_object_size(1, ossl_i2d_ASN1_TYPE(asn1, NULL), tn);
if(!(buf = OPENSSL_malloc(len))){
ossl_ASN1_TYPE_free(asn1);
ossl_raise(eASN1Error, "cannot alloc buffer");
}
p = buf;
if (tc == V_ASN1_UNIVERSAL) {
ossl_i2d_ASN1_TYPE(asn1, &p);
} else if (explicit) {
ASN1_put_object(&p, 1, ossl_i2d_ASN1_TYPE(asn1, NULL), tn, tc);
ossl_i2d_ASN1_TYPE(asn1, &p);
} else {
示例7: ossl_asn1data_to_der
static VALUE
ossl_asn1data_to_der(VALUE self, SEL sel)
{
VALUE value, der;
int tag, tag_class, is_cons = 0;
long length;
unsigned char *p;
value = ossl_asn1_get_value(self);
if(rb_obj_is_kind_of(value, rb_cArray)){
is_cons = 1;
value = join_der(value);
}
StringValue(value);
tag = ossl_asn1_tag(self);
tag_class = ossl_asn1_tag_class(self);
if((length = ASN1_object_size(1, RSTRING_LEN(value), tag)) <= 0)
ossl_raise(eASN1Error, NULL);
der = rb_bstr_new();
rb_bstr_resize(der, length);
p = (unsigned char *)rb_bstr_bytes(der);
ASN1_put_object(&p, is_cons, RSTRING_LEN(value), tag, tag_class);
memcpy(p, RSTRING_PTR(value), RSTRING_LEN(value));
p += RSTRING_LEN(value);
ossl_str_adjust(der, p);
return der;
}
示例8: asn1_i2d_ex_primitive
static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
const ASN1_ITEM *it, int tag, int aclass)
{
int len;
int utype;
int usetag;
int ndef = 0;
utype = it->utype;
/*
* Get length of content octets and maybe find out the underlying type.
*/
len = asn1_ex_i2c(pval, NULL, &utype, it);
/*
* If SEQUENCE, SET or OTHER then header is included in pseudo content
* octets so don't include tag+length. We need to check here because the
* call to asn1_ex_i2c() could change utype.
*/
if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
(utype == V_ASN1_OTHER))
usetag = 0;
else
usetag = 1;
/* -1 means omit type */
if (len == -1)
return 0;
/* -2 return is special meaning use ndef */
if (len == -2) {
ndef = 2;
len = 0;
}
/* If not implicitly tagged get tag from underlying type */
if (tag == -1)
tag = utype;
/* Output tag+length followed by content octets */
if (out) {
if (usetag)
ASN1_put_object(out, ndef, len, tag, aclass);
asn1_ex_i2c(pval, *out, &utype, it);
if (ndef)
ASN1_put_eoc(out);
else
*out += len;
}
if (usetag)
return ASN1_object_size(ndef, len, tag);
return len;
}
示例9: i2d_ASN1_BOOLEAN
int i2d_ASN1_BOOLEAN(int a, unsigned char **pp)
{
int r;
unsigned char *p;
r=ASN1_object_size(0,1,V_ASN1_BOOLEAN);
if (pp == NULL) return(r);
p= *pp;
ASN1_put_object(&p,0,1,V_ASN1_BOOLEAN,V_ASN1_UNIVERSAL);
*(p++)= (unsigned char)a;
*pp=p;
return(r);
}
示例10: ECDSA_size
size_t ECDSA_size(const EC_KEY *key) {
size_t ret, i, group_order_size;
ASN1_INTEGER bs;
BIGNUM *order = NULL;
unsigned char buf[4];
const EC_GROUP *group;
if (key->ecdsa_meth && key->ecdsa_meth->group_order_size) {
group_order_size = key->ecdsa_meth->group_order_size(key);
} else {
size_t num_bits;
if (key == NULL) {
return 0;
}
group = EC_KEY_get0_group(key);
if (group == NULL) {
return 0;
}
order = BN_new();
if (order == NULL) {
return 0;
}
if (!EC_GROUP_get_order(group, order, NULL)) {
BN_clear_free(order);
return 0;
}
num_bits = BN_num_bits(order);
group_order_size = (num_bits + 7) / 8;
}
bs.length = group_order_size;
bs.data = buf;
bs.type = V_ASN1_INTEGER;
/* If the top bit is set the ASN.1 encoding is 1 larger. */
buf[0] = 0xff;
i = i2d_ASN1_INTEGER(&bs, NULL);
i += i; /* r and s */
ret = ASN1_object_size(1, i, V_ASN1_SEQUENCE);
BN_clear_free(order);
return ret;
}
示例11: DSA_size
int DSA_size(DSA *r)
{
int ret,i;
ASN1_INTEGER bs;
unsigned char buf[4];
i=BN_num_bits(r->q);
bs.length=(i+7)/8;
bs.data=buf;
bs.type=V_ASN1_INTEGER;
/* If the top bit is set the asn1 encoding is 1 larger. */
buf[0]=0xff;
i=i2d_ASN1_INTEGER(&bs,NULL);
i+=i; /* r and s */
ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
return(ret);
}
示例12: i2d_ASN1_OBJECT
int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
{
unsigned char *p;
int objsize;
if ((a == NULL) || (a->data == NULL)) return(0);
objsize = ASN1_object_size(0,a->length,V_ASN1_OBJECT);
if (pp == NULL) return objsize;
p= *pp;
ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
memcpy(p,a->data,a->length);
p+=a->length;
*pp=p;
return(objsize);
}
示例13: DSA_size
int DSA_size(const DSA *dsa) {
int ret, i;
ASN1_INTEGER bs;
unsigned char buf[4]; /* 4 bytes looks really small.
However, i2d_ASN1_INTEGER() will not look
beyond the first byte, as long as the second
parameter is NULL. */
i = BN_num_bits(dsa->q);
bs.length = (i + 7) / 8;
bs.data = buf;
bs.type = V_ASN1_INTEGER;
/* If the top bit is set the asn1 encoding is 1 larger. */
buf[0] = 0xff;
i = i2d_ASN1_INTEGER(&bs, NULL);
i += i; /* r and s */
ret = ASN1_object_size(1, i, V_ASN1_SEQUENCE);
return ret;
}
示例14: ASN1_TYPE_set_int_octetstring
int
ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data,
int len)
{
int n, size;
ASN1_OCTET_STRING os, *osp;
ASN1_INTEGER in;
unsigned char *p;
unsigned char buf[32]; /* when they have 256bit longs,
* I'll be in trouble */
in.data = buf;
in.length = 32;
os.data = data;
os.type = V_ASN1_OCTET_STRING;
os.length = len;
ASN1_INTEGER_set(&in, num);
n = i2d_ASN1_INTEGER(&in, NULL);
n += M_i2d_ASN1_OCTET_STRING(&os, NULL);
size = ASN1_object_size(1, n, V_ASN1_SEQUENCE);
if ((osp = ASN1_STRING_new()) == NULL)
return (0);
/* Grow the 'string' */
if (!ASN1_STRING_set(osp, NULL, size)) {
ASN1_STRING_free(osp);
return (0);
}
M_ASN1_STRING_length_set(osp, size);
p = M_ASN1_STRING_data(osp);
ASN1_put_object(&p, 1,n, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
i2d_ASN1_INTEGER(&in, &p);
M_i2d_ASN1_OCTET_STRING(&os, &p);
ASN1_TYPE_set(a, V_ASN1_SEQUENCE, osp);
return (1);
}
示例15: add_signed_seq2string
/* ########################################### */
int
add_signed_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2)
{
/* To add an object of OID 1.9.999, which is a sequence containing
* 2 octet strings */
unsigned char *p;
ASN1_OCTET_STRING *os1, *os2;
ASN1_STRING *seq;
unsigned char *data;
int i, total;
if (signed_seq2string_nid == -1)
signed_seq2string_nid =
OBJ_create("1.9.9999","OID_example","Our example OID");
os1 = ASN1_OCTET_STRING_new();
os2 = ASN1_OCTET_STRING_new();
ASN1_OCTET_STRING_set(os1, (unsigned char*)str1, strlen(str1));
ASN1_OCTET_STRING_set(os2, (unsigned char*)str1, strlen(str1));
i = i2d_ASN1_OCTET_STRING(os1, NULL);
i += i2d_ASN1_OCTET_STRING(os2, NULL);
total = ASN1_object_size(1, i, V_ASN1_SEQUENCE);
data = malloc(total);
p = data;
ASN1_put_object(&p, 1,i, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
i2d_ASN1_OCTET_STRING(os1, &p);
i2d_ASN1_OCTET_STRING(os2, &p);
seq = ASN1_STRING_new();
ASN1_STRING_set(seq, data, total);
free(data);
ASN1_OCTET_STRING_free(os1);
ASN1_OCTET_STRING_free(os2);
PKCS7_add_signed_attribute(si, signed_seq2string_nid,
V_ASN1_SEQUENCE, (char *)seq);
return (1);
}