example.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/asn1_mac.h>
{
* time (in seconds) */
V_ASN1_UTCTIME,(char *)sign_time);
return(1);
}
{
return NULL;
}
static int signed_string_nid= -1;
{
/* To a an object of OID 1.2.3.4.5, which is an octet string */
if (signed_string_nid == -1)
/* When we add, we do not free */
V_ASN1_OCTET_STRING,(char *)os);
}
{
int i;
if (signed_string_nid == -1)
/* To retrieve */
{
{
if ((i+1) > len)
i=len-1;
return(i);
}
}
return(0);
}
static int signed_seq2string_nid= -1;
/* ########################################### */
{
/* To add an object of OID 1.9.999, which is a sequence containing
* 2 octet strings */
unsigned char *p;
unsigned char *data;
int i,total;
if (signed_seq2string_nid == -1)
p=data;
i2d_ASN1_OCTET_STRING(os1,&p);
i2d_ASN1_OCTET_STRING(os2,&p);
V_ASN1_SEQUENCE,(char *)seq);
return(1);
}
/* For this case, I will malloc the return strings */
{
if (signed_seq2string_nid == -1)
/* To retrieve */
{
ASN1_CTX c;
ASN1_STRING *s;
long length;
c.p=ASN1_STRING_data(s);
c.max=c.p+ASN1_STRING_length(s);
/* Length is the length of the seqence */
c.q=c.p;
goto err;
c.slen-=(c.p-c.q);
c.q=c.p;
goto err;
c.slen-=(c.p-c.q);
if (!asn1_Finish(&c)) goto err;
return(1);
}
err:
return(0);
}
/* #######################################
* THE OTHER WAY TO DO THINGS
* #######################################
*/
X509_ATTRIBUTE *create_time(void)
{
* time (in seconds) */
V_ASN1_UTCTIME,(char *)sign_time);
return(ret);
}
{
return NULL;
}
{
/* To a an object of OID 1.2.3.4.5, which is an octet string */
if (signed_string_nid == -1)
/* When we add, we do not free */
V_ASN1_OCTET_STRING,(char *)os);
return(ret);
}
{
int i;
if (signed_string_nid == -1)
/* To retrieve */
{
{
if ((i+1) > len)
i=len-1;
return(i);
}
}
return(0);
}
{
/* To add an object of OID 1.9.999, which is a sequence containing
* 2 octet strings */
unsigned char *p;
unsigned char *data;
int i,total;
if (signed_seq2string_nid == -1)
p=data;
i2d_ASN1_OCTET_STRING(os1,&p);
i2d_ASN1_OCTET_STRING(os2,&p);
V_ASN1_SEQUENCE,(char *)seq);
return(ret);
}
/* For this case, I will malloc the return strings */
{
if (signed_seq2string_nid == -1)
/* To retrieve */
{
ASN1_CTX c;
ASN1_STRING *s;
long length;
c.p=ASN1_STRING_data(s);
c.max=c.p+ASN1_STRING_length(s);
/* Length is the length of the seqence */
c.q=c.p;
goto err;
c.slen-=(c.p-c.q);
c.q=c.p;
goto err;
c.slen-=(c.p-c.q);
if (!asn1_Finish(&c)) goto err;
return(1);
}
err:
return(0);
}