summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFabio Fiorina <fiorinaf@gnutls.org>2003-02-03 21:23:19 +0000
committerFabio Fiorina <fiorinaf@gnutls.org>2003-02-03 21:23:19 +0000
commit1525a7131ec9640b81c2b88a2ab08f779256bd24 (patch)
treef1d2ba2d9fffa1ed3e7a00e44d3e5fd20075d56f /src
parent7536e294f0bb2db539fd47a097761b0abe3f8d9a (diff)
downloadlibtasn1-1525a7131ec9640b81c2b88a2ab08f779256bd24.tar.gz
libtasn1-1525a7131ec9640b81c2b88a2ab08f779256bd24.tar.bz2
libtasn1-1525a7131ec9640b81c2b88a2ab08f779256bd24.zip
change asn1_create_element interface
Diffstat (limited to 'src')
-rw-r--r--src/CertificateExample.c220
-rw-r--r--src/CrlExample.c134
-rw-r--r--src/asn1Coding.c20
-rw-r--r--src/asn1Decoding.c35
-rw-r--r--src/asn1Parser.c14
5 files changed, 202 insertions, 221 deletions
diff --git a/src/CertificateExample.c b/src/CertificateExample.c
index 549804a..2f3bf96 100644
--- a/src/CertificateExample.c
+++ b/src/CertificateExample.c
@@ -105,15 +105,13 @@ get_Name_type(node_asn *cert_def,node_asn *cert,char *root, char *answer)
str2,&len);
if(!strcmp(str,str2)){
asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationName",
- &value,"certificate2-subject-C");
+ &value);
len = sizeof(str) - 1;
asn1_read_value(cert,name3,str,&len);
asn1_der_decoding(&value,str,len,errorDescription);
- strcpy(name3,"certificate2-subject-C");
len = sizeof(str) - 1;
- asn1_read_value(value,name3,str,&len); /* CHOICE */
- strcat(name3,".");
- strcat(name3,str);
+ asn1_read_value(value,"",str,&len); /* CHOICE */
+ strcpy(name3,str);
len = sizeof(str) - 1;
asn1_read_value(value,name3,str,&len);
str[len]=0;
@@ -127,15 +125,13 @@ get_Name_type(node_asn *cert_def,node_asn *cert,char *root, char *answer)
,str2,&len);
if(!strcmp(str,str2)){
asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationName"
- ,&value,"certificate2-subject-O");
+ ,&value);
len = sizeof(str) - 1;
asn1_read_value(cert,name3,str,&len);
asn1_der_decoding(&value,str,len,errorDescription);
- strcpy(name3,"certificate2-subject-O");
len = sizeof(str) - 1;
- asn1_read_value(value,name3,str,&len); /* CHOICE */
- strcat(name3,".");
- strcat(name3,str);
+ asn1_read_value(value,"",str,&len); /* CHOICE */
+ strcpy(name3,str);
len = sizeof(str) - 1;
asn1_read_value(value,name3,str,&len);
str[len]=0;
@@ -147,15 +143,13 @@ get_Name_type(node_asn *cert_def,node_asn *cert,char *root, char *answer)
len = sizeof(str2) - 1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-at-organizationalUnitName",str2,&len);
if(!strcmp(str,str2)){
- asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationalUnitName",&value,"certificate2-subject-OU");
+ asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationalUnitName",&value);
len = sizeof(str) - 1;
asn1_read_value(cert,name3,str,&len);
asn1_der_decoding(&value,str,len,errorDescription);
- strcpy(name3,"certificate2-subject-OU");
len = sizeof(str) - 1;
- asn1_read_value(value,name3,str,&len); /* CHOICE */
- strcat(name3,".");
- strcat(name3,str);
+ asn1_read_value(value,"",str,&len); /* CHOICE */
+ strcpy(name3,str);
len = sizeof(str) - 1;
asn1_read_value(value,name3,str,&len);
str[len]=0;
@@ -193,214 +187,212 @@ create_certificate(node_asn *cert_def,unsigned char *der,int *der_len)
ASN1_TYPE constr=ASN1_TYPE_EMPTY;
char errorDescription[MAX_ERROR_DESCRIPTION_SIZE];
- result=asn1_create_element(cert_def,"PKIX1Implicit88.Certificate",&cert1,"certificate1");
+ result=asn1_create_element(cert_def,"PKIX1Implicit88.Certificate",&cert1);
/* Use the next 3 lines to visit the empty certificate */
/* printf("-----------------\n");
- asn1_visit_tree(cert1,"certificate1");
+ asn1_visit_tree(cert1,"");
printf("-----------------\n"); */
/* version: v3(2) */
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.version","v3",0);
+ result=asn1_write_value(cert1,"tbsCertificate.version","v3",0);
/* serialNumber: 17 */
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.serialNumber","17",0);
+ result=asn1_write_value(cert1,"tbsCertificate.serialNumber","17",0);
/* signature: dsa-with-sha1 */
len = sizeof(str) - 1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-dsa-with-sha1",str,&len);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.signature.algorithm",
+ result=asn1_write_value(cert1,"tbsCertificate.signature.algorithm",
str,1);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.signature.parameters",
+ result=asn1_write_value(cert1,"tbsCertificate.signature.parameters",
NULL,0);
/* issuer: Country="US" Organization="gov" OrganizationUnit="nist" */
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.issuer","rdnSequence",12);
+ result=asn1_write_value(cert1,"tbsCertificate.issuer","rdnSequence",12);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.issuer.rdnSequence","NEW",1);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.issuer.rdnSequence.?LAST","NEW",1);
+ result=asn1_write_value(cert1,"tbsCertificate.issuer.rdnSequence","NEW",1);
+ result=asn1_write_value(cert1,"tbsCertificate.issuer.rdnSequence.?LAST","NEW",1);
/* C */
len = sizeof(str) - 1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-at-countryName",str,&len);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.issuer.rdnSequence.?LAST.?LAST.type",str,1);
+ result=asn1_write_value(cert1,"tbsCertificate.issuer.rdnSequence.?LAST.?LAST.type",str,1);
result=asn1_create_element(cert_def,"PKIX1Implicit88.X520countryName",
- &value,"countryName");
- result=asn1_write_value(value,"countryName","US",2);
- result=asn1_der_coding(value,"countryName",der,der_len,errorDescription);
+ &value);
+ result=asn1_write_value(value,"","US",2);
+ result=asn1_der_coding(value,"",der,der_len,errorDescription);
asn1_delete_structure(&value);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len);
+ result=asn1_write_value(cert1,"tbsCertificate.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.issuer.rdnSequence","NEW",1);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.issuer.rdnSequence.?LAST","NEW",1);
+ result=asn1_write_value(cert1,"tbsCertificate.issuer.rdnSequence","NEW",1);
+ result=asn1_write_value(cert1,"tbsCertificate.issuer.rdnSequence.?LAST","NEW",1);
/* O */
len = sizeof(str) - 1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-at-organizationName",str,&len);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.issuer.rdnSequence.?LAST.?LAST.type",str,1);
+ result=asn1_write_value(cert1,"tbsCertificate.issuer.rdnSequence.?LAST.?LAST.type",str,1);
result=asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationName",
- &value,"OrgName");
- result=asn1_write_value(value,"OrgName","printableString",1);
- result=asn1_write_value(value,"OrgName.printableString","gov",3);
- result=asn1_der_coding(value,"OrgName",der,der_len,errorDescription);
+ &value);
+ result=asn1_write_value(value,"","printableString",1);
+ result=asn1_write_value(value,"printableString","gov",3);
+ result=asn1_der_coding(value,"",der,der_len,errorDescription);
asn1_delete_structure(&value);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len);
+ result=asn1_write_value(cert1,"tbsCertificate.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.issuer.rdnSequence","NEW",1);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.issuer.rdnSequence.?LAST","NEW",1);
+ result=asn1_write_value(cert1,"tbsCertificate.issuer.rdnSequence","NEW",1);
+ result=asn1_write_value(cert1,"tbsCertificate.issuer.rdnSequence.?LAST","NEW",1);
/* OU */
len = sizeof(str) - 1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-at-organizationalUnitName",
str,&len);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.issuer.rdnSequence.?LAST.?LAST.type",str,1);
- result=asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationalUnitName",&value,"OrgUnitName");
- result=asn1_write_value(value,"OrgUnitName","printableString",1);
- result=asn1_write_value(value,"OrgUnitName.printableString","nist",4);
- result=asn1_der_coding(value,"OrgUnitName",der,der_len,errorDescription);
+ result=asn1_write_value(cert1,"tbsCertificate.issuer.rdnSequence.?LAST.?LAST.type",str,1);
+ result=asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationalUnitName",&value);
+ result=asn1_write_value(value,"","printableString",1);
+ result=asn1_write_value(value,"printableString","nist",4);
+ result=asn1_der_coding(value,"",der,der_len,errorDescription);
asn1_delete_structure(&value);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len);
+ result=asn1_write_value(cert1,"tbsCertificate.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len);
/* validity */
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.validity.notBefore","utcTime",1);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.validity.notBefore.utcTime","970630000000Z",1);
+ result=asn1_write_value(cert1,"tbsCertificate.validity.notBefore","utcTime",1);
+ result=asn1_write_value(cert1,"tbsCertificate.validity.notBefore.utcTime","970630000000Z",1);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.validity.notAfter","utcTime",1);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.validity.notAfter.utcTime","971231000000Z",1);
+ result=asn1_write_value(cert1,"tbsCertificate.validity.notAfter","utcTime",1);
+ result=asn1_write_value(cert1,"tbsCertificate.validity.notAfter.utcTime","971231000000Z",1);
/* subject: Country="US" Organization="gov" OrganizationUnit="nist" */
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subject","rdnSequence",1);
+ result=asn1_write_value(cert1,"tbsCertificate.subject","rdnSequence",1);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subject.rdnSequence","NEW",1);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subject.rdnSequence.?LAST","NEW",1);
+ result=asn1_write_value(cert1,"tbsCertificate.subject.rdnSequence","NEW",1);
+ result=asn1_write_value(cert1,"tbsCertificate.subject.rdnSequence.?LAST","NEW",1);
/* C */
len = sizeof(str) - 1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-at-countryName",str,&len);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subject.rdnSequence.?LAST.?LAST.type",str,1);
+ result=asn1_write_value(cert1,"tbsCertificate.subject.rdnSequence.?LAST.?LAST.type",str,1);
result=asn1_create_element(cert_def,"PKIX1Implicit88.X520countryName",
- &value,"countryName");
- result=asn1_write_value(value,"countryName","US",2);
- result=asn1_der_coding(value,"countryName",der,der_len,errorDescription);
+ &value);
+ result=asn1_write_value(value,"","US",2);
+ result=asn1_der_coding(value,"",der,der_len,errorDescription);
asn1_delete_structure(&value);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subject.rdnSequence.?LAST.?LAST.value",der,*der_len);
+ result=asn1_write_value(cert1,"tbsCertificate.subject.rdnSequence.?LAST.?LAST.value",der,*der_len);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subject.rdnSequence","NEW",4);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subject.rdnSequence.?LAST","NEW",4);
+ result=asn1_write_value(cert1,"tbsCertificate.subject.rdnSequence","NEW",4);
+ result=asn1_write_value(cert1,"tbsCertificate.subject.rdnSequence.?LAST","NEW",4);
/* O */
len = sizeof(str) - 1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-at-organizationName",str,&len);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subject.rdnSequence.?LAST.?LAST.type",str,1);
+ result=asn1_write_value(cert1,"tbsCertificate.subject.rdnSequence.?LAST.?LAST.type",str,1);
result=asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationName",
- &value,"OrgName");
- result=asn1_write_value(value,"OrgName","printableString",1);
- result=asn1_write_value(value,"OrgName.printableString","gov",3);
- result=asn1_der_coding(value,"OrgName",der,der_len,errorDescription);
+ &value);
+ result=asn1_write_value(value,"","printableString",1);
+ result=asn1_write_value(value,"printableString","gov",3);
+ result=asn1_der_coding(value,"",der,der_len,errorDescription);
asn1_delete_structure(&value);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subject.rdnSequence.?LAST.?LAST.value",der,*der_len);
+ result=asn1_write_value(cert1,"tbsCertificate.subject.rdnSequence.?LAST.?LAST.value",der,*der_len);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subject.rdnSequence","NEW",4);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subject.rdnSequence.?LAST","NEW",4);
+ result=asn1_write_value(cert1,"tbsCertificate.subject.rdnSequence","NEW",4);
+ result=asn1_write_value(cert1,"tbsCertificate.subject.rdnSequence.?LAST","NEW",4);
/* OU */
len = sizeof(str) - 1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-at-organizationalUnitName",
str,&len);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subject.rdnSequence.?LAST.?LAST.type",str,1);
- result=asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationalUnitName",&value,"OrgUnitName");
- result=asn1_write_value(value,"OrgUnitName","printableString",1);
- result=asn1_write_value(value,"OrgUnitName.printableString","nist",4);
- result=asn1_der_coding(value,"OrgUnitName",der,der_len,errorDescription);
+ result=asn1_write_value(cert1,"tbsCertificate.subject.rdnSequence.?LAST.?LAST.type",str,1);
+ result=asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationalUnitName",&value);
+ result=asn1_write_value(value,"","printableString",1);
+ result=asn1_write_value(value,"printableString","nist",4);
+ result=asn1_der_coding(value,"",der,der_len,errorDescription);
asn1_delete_structure(&value);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subject.rdnSequence.?LAST.?LAST.value",der,*der_len);
+ result=asn1_write_value(cert1,"tbsCertificate.subject.rdnSequence.?LAST.?LAST.value",der,*der_len);
/* subjectPublicKeyInfo: dsa with parameters=Dss-Parms */
len = sizeof(str) - 1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-dsa",str,&len);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subjectPublicKeyInfo.algorithm.algorithm",str,1);
- result=asn1_create_element(cert_def,"PKIX1Implicit88.Dss-Parms",&param,"parameters");
+ result=asn1_write_value(cert1,"tbsCertificate.subjectPublicKeyInfo.algorithm.algorithm",str,1);
+ result=asn1_create_element(cert_def,"PKIX1Implicit88.Dss-Parms",&param);
str2="\xd4\x38"; /* only an example */
- result=asn1_write_value(param,"parameters.p",str2,128);
+ result=asn1_write_value(param,"p",str2,128);
str2="\xd4\x38"; /* only an example */
- result=asn1_write_value(param,"parameters.q",str2,20);
+ result=asn1_write_value(param,"q",str2,20);
str2="\xd4\x38"; /* only an example */
- result=asn1_write_value(param,"parameters.g",str2,128);
- result=asn1_der_coding(param,"parameters",der,der_len,errorDescription);
+ result=asn1_write_value(param,"g",str2,128);
+ result=asn1_der_coding(param,"",der,der_len,errorDescription);
asn1_delete_structure(&param);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subjectPublicKeyInfo.algorithm.parameters",der,*der_len);
+ result=asn1_write_value(cert1,"tbsCertificate.subjectPublicKeyInfo.algorithm.parameters",der,*der_len);
/* subjectPublicKey */
str2="\x02\x81"; /* only an example */
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subjectPublicKeyInfo.subjectPublicKey",str2,1048);
+ result=asn1_write_value(cert1,"tbsCertificate.subjectPublicKeyInfo.subjectPublicKey",str2,1048);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.issuerUniqueID",NULL,0); /* NO OPTION */
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.subjectUniqueID",NULL,0); /* NO OPTION */
+ result=asn1_write_value(cert1,"tbsCertificate.issuerUniqueID",NULL,0); /* NO OPTION */
+ result=asn1_write_value(cert1,"tbsCertificate.subjectUniqueID",NULL,0); /* NO OPTION */
/* extensions */
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.extensions","NEW",1);
+ result=asn1_write_value(cert1,"tbsCertificate.extensions","NEW",1);
len = sizeof(str) - 1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-ce-basicConstraints",
str,&len);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.extensions.?LAST.extnID",str,1); /* basicConstraints */
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.extensions.?LAST.critical","TRUE",1);
- result=asn1_create_element(cert_def,"PKIX1Implicit88.BasicConstraints",&constr,
- "basicConstraints1");
- result=asn1_write_value(constr,"basicConstraints1.cA","TRUE",1);
- result=asn1_write_value(constr,"basicConstraints1.pathLenConstraint",NULL,0);
- result=asn1_der_coding(constr,"basicConstraints1",der,der_len,errorDescription);
+ result=asn1_write_value(cert1,"tbsCertificate.extensions.?LAST.extnID",str,1); /* basicConstraints */
+ result=asn1_write_value(cert1,"tbsCertificate.extensions.?LAST.critical","TRUE",1);
+ result=asn1_create_element(cert_def,"PKIX1Implicit88.BasicConstraints",&constr);
+ result=asn1_write_value(constr,"cA","TRUE",1);
+ result=asn1_write_value(constr,"pathLenConstraint",NULL,0);
+ result=asn1_der_coding(constr,"",der,der_len,errorDescription);
result=asn1_delete_structure(&constr);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.extensions.?LAST.extnValue",der,*der_len);
+ result=asn1_write_value(cert1,"tbsCertificate.extensions.?LAST.extnValue",der,*der_len);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.extensions","NEW",1);
+ result=asn1_write_value(cert1,"tbsCertificate.extensions","NEW",1);
len = sizeof(str) - 1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-ce-subjectKeyIdentifier",
str,&len);
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.extensions.?LAST.extnID",str,1); /* subjectKeyIdentifier */
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.extensions.?LAST.critical","FALSE",1);
+ result=asn1_write_value(cert1,"tbsCertificate.extensions.?LAST.extnID",str,1); /* subjectKeyIdentifier */
+ result=asn1_write_value(cert1,"tbsCertificate.extensions.?LAST.critical","FALSE",1);
str2="\x04\x14\xe7\x26\xc5"; /* only an example */
- result=asn1_write_value(cert1,"certificate1.tbsCertificate.extensions.?LAST.extnValue",str2,22);
+ result=asn1_write_value(cert1,"tbsCertificate.extensions.?LAST.extnValue",str2,22);
/* signatureAlgorithm: dsa-with-sha */
len = sizeof(str) - 1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-dsa-with-sha1",str,&len);
- result=asn1_write_value(cert1,"certificate1.signatureAlgorithm.algorithm",str,1);
- result=asn1_write_value(cert1,"certificate1.signatureAlgorithm.parameters",NULL,0); /* NO OPTION */
+ result=asn1_write_value(cert1,"signatureAlgorithm.algorithm",str,1);
+ result=asn1_write_value(cert1,"signatureAlgorithm.parameters",NULL,0); /* NO OPTION */
/* signature */
- result=asn1_der_coding(cert1,"certificate1.tbsCertificate",der,der_len
+ result=asn1_der_coding(cert1,"tbsCertificate",der,der_len
,errorDescription);
if(result!=ASN1_SUCCESS){
printf("\n'tbsCertificate' encoding creation: ERROR\n");
- // return;
}
/* add the lines for the signature on der[0]..der[der_len-1]: result in str2 */
- result=asn1_write_value(cert1,"certificate1.signature",str2,368); /* dsa-with-sha */
+ result=asn1_write_value(cert1,"signature",str2,368); /* dsa-with-sha */
/* Use the next 3 lines to visit the certificate */
/* printf("-----------------\n");
- asn1_visit_tree(cert1,"certificate1");
+ asn1_visit_tree(cert1,"");
printf("-----------------\n"); */
- result=asn1_der_coding(cert1,"certificate1",der,der_len,errorDescription);
+ result=asn1_der_coding(cert1,"",der,der_len,errorDescription);
if(result!=ASN1_SUCCESS){
- printf("\n'certificate1' encoding creation: ERROR\n");
+ printf("\n'certificate' encoding creation: ERROR\n");
return;
}
/* Print the 'Certificate1' DER encoding */
- printf("-----------------\nCertificate1 Encoding:\nNumber of bytes=%i\n",*der_len);
+ printf("-----------------\nCertificate Encoding:\nNumber of bytes=%i\n",*der_len);
for(k=0;k<*der_len;k++) printf("%02x ",der[k]);
printf("\n-----------------\n");
@@ -427,7 +419,7 @@ get_certificate(node_asn *cert_def,unsigned char *der,int der_len)
ASN1_TYPE cert2=ASN1_TYPE_EMPTY;
char errorDescription[MAX_ERROR_DESCRIPTION_SIZE];
- asn1_create_element(cert_def,"PKIX1Implicit88.Certificate",&cert2,"certificate2");
+ asn1_create_element(cert_def,"PKIX1Implicit88.Certificate",&cert2);
result=asn1_der_decoding(&cert2,der,der_len,errorDescription);
@@ -438,16 +430,16 @@ get_certificate(node_asn *cert_def,unsigned char *der,int der_len)
/* issuer */
- get_Name_type(cert_def,cert2,"certificate2.tbsCertificate.issuer",str);
- printf("certificate2:\nissuer =%s\n",str);
+ get_Name_type(cert_def,cert2,"tbsCertificate.issuer",str);
+ printf("certificate:\nissuer :%s\n",str);
/* subject */
- get_Name_type(cert_def,cert2,"certificate2.tbsCertificate.subject",str);
- printf("subject=%s\n",str);
+ get_Name_type(cert_def,cert2,"tbsCertificate.subject",str);
+ printf("subject:%s\n",str);
/* Verify sign */
len = sizeof(str) - 1;
- result=asn1_read_value(cert2,"certificate2.signatureAlgorithm.algorithm"
+ result=asn1_read_value(cert2,"signatureAlgorithm.algorithm"
,str,&len);
len = sizeof(str2) - 1;
@@ -455,19 +447,19 @@ get_certificate(node_asn *cert_def,unsigned char *der,int der_len)
if(!strcmp(str,str2)){ /* dsa-with-sha */
result=asn1_der_decoding_startEnd(cert2,der,der_len,
- "certificate2.tbsCertificate",&start,&end);
+ "tbsCertificate",&start,&end);
/* add the lines to calculate the sha on der[start]..der[end] */
len = sizeof(str) - 1;
- result=asn1_read_value(cert2,"certificate2.signature",str,&len);
+ result=asn1_read_value(cert2,"signature",str,&len);
/* compare the previous value to signature ( with issuer public key) */
}
/* Use the next 3 lines to visit the certificate */
/* printf("-----------------\n");
- asn1_visit_tree(cert2,"certificate2");
+ asn1_visit_tree(cert2,"");
printf("-----------------\n"); */
diff --git a/src/CrlExample.c b/src/CrlExample.c
index b88abb0..1aafbd7 100644
--- a/src/CrlExample.c
+++ b/src/CrlExample.c
@@ -110,17 +110,15 @@ get_Name_type(node_asn *cert_def,node_asn *cert,char *root, char *answer)
str2,&len);
if(!strcmp(str,str2)){
asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationName",
- &value,"certificate2-subject-C");
+ &value);
len = sizeof(str)-1;
asn1_read_value(cert,name3,str,&len);
result=asn1_der_decoding(&value,str,len,errorDescription);
- strcpy(name3,"certificate2-subject-C");
len = sizeof(str)-1;
- asn1_read_value(value,name3,str,&len); /* CHOICE */
+ asn1_read_value(value,"",str,&len); /* CHOICE */
- strcat(name3,".");
- strcat(name3,str);
+ strcpy(name3,str);
len = sizeof(str)-1;
asn1_read_value(value,name3,str,&len);
@@ -136,16 +134,14 @@ get_Name_type(node_asn *cert_def,node_asn *cert,char *root, char *answer)
,str2,&len);
if(!strcmp(str,str2)){
asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationName"
- ,&value,"certificate2-subject-O");
+ ,&value);
len = sizeof(str)-1;
asn1_read_value(cert,name3,str,&len);
asn1_der_decoding(&value,str,len,errorDescription);
- strcpy(name3,"certificate2-subject-O");
len = sizeof(str)-1;
- asn1_read_value(value,name3,str,&len); /* CHOICE */
- strcat(name3,".");
- strcat(name3,str);
+ asn1_read_value(value,"",str,&len); /* CHOICE */
+ strcpy(name3,str);
len = sizeof(str)-1;
asn1_read_value(value,name3,str,&len);
str[len]=0;
@@ -157,15 +153,13 @@ get_Name_type(node_asn *cert_def,node_asn *cert,char *root, char *answer)
len = sizeof(str2);
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-at-organizationalUnitName",str2,&len);
if(!strcmp(str,str2)){
- asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationalUnitName",&value,"certificate2-subject-OU");
+ asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationalUnitName",&value);
len = sizeof(str)-1;
asn1_read_value(cert,name3,str,&len);
asn1_der_decoding(&value,str,len,errorDescription);
- strcpy(name3,"certificate2-subject-OU");
len = sizeof(str)-1;
- asn1_read_value(value,name3,str,&len); /* CHOICE */
- strcat(name3,".");
- strcat(name3,str);
+ asn1_read_value(value,"",str,&len); /* CHOICE */
+ strcpy(name3,str);
len = sizeof(str)-1;
asn1_read_value(value,name3,str,&len);
str[len]=0;
@@ -201,126 +195,126 @@ create_CRL(node_asn *cert_def, unsigned char *der,int *der_len)
ASN1_TYPE value=ASN1_TYPE_EMPTY;
char errorDescription[MAX_ERROR_DESCRIPTION_SIZE];
- result=asn1_create_element(cert_def,"PKIX1Implicit88.CertificateList",&crl,"crl1");
+ result=asn1_create_element(cert_def,"PKIX1Implicit88.CertificateList",&crl);
/* Use the next 3 lines to visit the empty certificate */
/* printf("-----------------\n");
- asn1_visit_tree(crl,"crl1");
+ asn1_visit_tree(crl,"");
printf("-----------------\n"); */
/* version: v2(1) */
- result=asn1_write_value(crl,"crl1.tbsCertList.version","v2",0);
+ result=asn1_write_value(crl,"tbsCertList.version","v2",0);
/* signature: dsa-with-sha */
len = sizeof(str)-1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-dsa-with-sha1",str,&len);
- result=asn1_write_value(crl,"crl1.tbsCertList.signature.algorithm",str,1);
- result=asn1_write_value(crl,"crl1.tbsCertList.signature.parameters",NULL,0);
+ result=asn1_write_value(crl,"tbsCertList.signature.algorithm",str,1);
+ result=asn1_write_value(crl,"tbsCertList.signature.parameters",NULL,0);
/* issuer: Country="US" Organization="gov" OrganizationUnit="nist" */
- result=asn1_write_value(crl,"crl1.tbsCertList.issuer","rdnSequence",1);
+ result=asn1_write_value(crl,"tbsCertList.issuer","rdnSequence",1);
- result=asn1_write_value(crl,"crl1.tbsCertList.issuer.rdnSequence","NEW",1);
- result=asn1_write_value(crl,"crl1.tbsCertList.issuer.rdnSequence.?LAST","NEW",1);
+ result=asn1_write_value(crl,"tbsCertList.issuer.rdnSequence","NEW",1);
+ result=asn1_write_value(crl,"tbsCertList.issuer.rdnSequence.?LAST","NEW",1);
/* C */
len = sizeof(str)-1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-at-countryName",str,&len);
- result=asn1_write_value(crl,"crl1.tbsCertList.issuer.rdnSequence.?LAST.?LAST.type",str,1);
+ result=asn1_write_value(crl,"tbsCertList.issuer.rdnSequence.?LAST.?LAST.type",str,1);
result=asn1_create_element(cert_def,"PKIX1Implicit88.X520countryName",
- &value,"countryName");
- result=asn1_write_value(value,"countryName","US",2);
- result=asn1_der_coding(value,"countryName",der,der_len,errorDescription);
+ &value);
+ result=asn1_write_value(value,"","US",2);
+ result=asn1_der_coding(value,"",der,der_len,errorDescription);
asn1_delete_structure(&value);
- result=asn1_write_value(crl,"crl1.tbsCertList.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len);
+ result=asn1_write_value(crl,"tbsCertList.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len);
- result=asn1_write_value(crl,"crl1.tbsCertList.issuer.rdnSequence","NEW",4);
- result=asn1_write_value(crl,"crl1.tbsCertList.issuer.rdnSequence.?LAST","NEW",4);
+ result=asn1_write_value(crl,"tbsCertList.issuer.rdnSequence","NEW",4);
+ result=asn1_write_value(crl,"tbsCertList.issuer.rdnSequence.?LAST","NEW",4);
/* O */
len = sizeof(str)-1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-at-organizationName",str,&len);
- result=asn1_write_value(crl,"crl1.tbsCertList.issuer.rdnSequence.?LAST.?LAST.type",str,8);
+ result=asn1_write_value(crl,"tbsCertList.issuer.rdnSequence.?LAST.?LAST.type",str,8);
result=asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationName",
- &value,"OrgName");
- result=asn1_write_value(value,"OrgName","printableString",1);
- result=asn1_write_value(value,"OrgName.printableString","gov",3);
- result=asn1_der_coding(value,"OrgName",der,der_len,errorDescription);
+ &value);
+ result=asn1_write_value(value,"","printableString",1);
+ result=asn1_write_value(value,"printableString","gov",3);
+ result=asn1_der_coding(value,"",der,der_len,errorDescription);
asn1_delete_structure(&value);
- result=asn1_write_value(crl,"crl1.tbsCertList.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len);
+ result=asn1_write_value(crl,"tbsCertList.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len);
- result=asn1_write_value(crl,"crl1.tbsCertList.issuer.rdnSequence","NEW",1);
- result=asn1_write_value(crl,"crl1.tbsCertList.issuer.rdnSequence.?LAST","NEW",1);
+ result=asn1_write_value(crl,"tbsCertList.issuer.rdnSequence","NEW",1);
+ result=asn1_write_value(crl,"tbsCertList.issuer.rdnSequence.?LAST","NEW",1);
/* OU */
len = sizeof(str)-1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-at-organizationalUnitName",
str,&len);
- result=asn1_write_value(crl,"crl1.tbsCertList.issuer.rdnSequence.?LAST.?LAST.type",str,1);
- result=asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationalUnitName",&value,"OrgUnitName");
- result=asn1_write_value(value,"OrgUnitName","printableString",1);
- result=asn1_write_value(value,"OrgUnitName.printableString","nist",4);
- result=asn1_der_coding(value,"OrgUnitName",der,der_len,errorDescription);
+ result=asn1_write_value(crl,"tbsCertList.issuer.rdnSequence.?LAST.?LAST.type",str,1);
+ result=asn1_create_element(cert_def,"PKIX1Implicit88.X520OrganizationalUnitName",&value);
+ result=asn1_write_value(value,"","printableString",1);
+ result=asn1_write_value(value,"printableString","nist",4);
+ result=asn1_der_coding(value,"",der,der_len,errorDescription);
asn1_delete_structure(&value);
- result=asn1_write_value(crl,"crl1.tbsCertList.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len);
+ result=asn1_write_value(crl,"tbsCertList.issuer.rdnSequence.?LAST.?LAST.value",der,*der_len);
/* validity */
- result=asn1_write_value(crl,"crl1.tbsCertList.thisUpdate","utcTime",1);
- result=asn1_write_value(crl,"crl1.tbsCertList.thisUpdate.utcTime","970801000000Z",1);
+ result=asn1_write_value(crl,"tbsCertList.thisUpdate","utcTime",1);
+ result=asn1_write_value(crl,"tbsCertList.thisUpdate.utcTime","970801000000Z",1);
- result=asn1_write_value(crl,"crl1.tbsCertList.nextUpdate","utcTime",1);
- result=asn1_write_value(crl,"crl1.tbsCertList.nextUpdate.utcTime","970808000000Z",1);
+ result=asn1_write_value(crl,"tbsCertList.nextUpdate","utcTime",1);
+ result=asn1_write_value(crl,"tbsCertList.nextUpdate.utcTime","970808000000Z",1);
/* revokedCertificates */
- result=asn1_write_value(crl,"crl1.tbsCertList.revokedCertificates","NEW",1);
+ result=asn1_write_value(crl,"tbsCertList.revokedCertificates","NEW",1);
str[0]=18;
- result=asn1_write_value(crl,"crl1.tbsCertList.revokedCertificates.?LAST.userCertificate",str,1);
- result=asn1_write_value(crl,"crl1.tbsCertList.revokedCertificates.?LAST.revocationDate","utcTime",1);
- result=asn1_write_value(crl,"crl1.tbsCertList.revokedCertificates.?LAST.revocationDate.utcTime","970731000000Z",1);
+ result=asn1_write_value(crl,"tbsCertList.revokedCertificates.?LAST.userCertificate",str,1);
+ result=asn1_write_value(crl,"tbsCertList.revokedCertificates.?LAST.revocationDate","utcTime",1);
+ result=asn1_write_value(crl,"tbsCertList.revokedCertificates.?LAST.revocationDate.utcTime","970731000000Z",1);
- result=asn1_write_value(crl,"crl1.tbsCertList.revokedCertificates.?LAST.crlEntryExtensions","NEW",1);
+ result=asn1_write_value(crl,"tbsCertList.revokedCertificates.?LAST.crlEntryExtensions","NEW",1);
len = sizeof(str)-1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-ce-cRLReasons",
str,&len);
- result=asn1_write_value(crl,"crl1.tbsCertList.revokedCertificates.?LAST.crlEntryExtensions.?LAST.extnID",str,1); /* reasonCode */
- result=asn1_write_value(crl,"crl1.tbsCertList.revokedCertificates.?LAST.crlEntryExtensions.?LAST.critical","FALSE",1);
+ result=asn1_write_value(crl,"tbsCertList.revokedCertificates.?LAST.crlEntryExtensions.?LAST.extnID",str,1); /* reasonCode */
+ result=asn1_write_value(crl,"tbsCertList.revokedCertificates.?LAST.crlEntryExtensions.?LAST.critical","FALSE",1);
str2="\x0a\x01\x01";
- result=asn1_write_value(crl,"crl1.tbsCertList.revokedCertificates.?LAST.crlEntryExtensions.?LAST.extnValue",str2,3);
+ result=asn1_write_value(crl,"tbsCertList.revokedCertificates.?LAST.crlEntryExtensions.?LAST.extnValue",str2,3);
/* crlExtensions */
- result=asn1_write_value(crl,"crl1.tbsCertList.crlExtensions",NULL,0);
+ result=asn1_write_value(crl,"tbsCertList.crlExtensions",NULL,0);
/* signatureAlgorithm: dsa-with-sha */
len = sizeof(str)-1;
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-dsa-with-sha1",str,&len);
- result=asn1_write_value(crl,"crl1.signatureAlgorithm.algorithm",str,1);
- result=asn1_write_value(crl,"crl1.signatureAlgorithm.parameters",NULL,0); /* NO OPTION */
+ result=asn1_write_value(crl,"signatureAlgorithm.algorithm",str,1);
+ result=asn1_write_value(crl,"signatureAlgorithm.parameters",NULL,0); /* NO OPTION */
/* signature */
- result=asn1_der_coding(crl,"crl1.tbsCertList",der,der_len,errorDescription);
+ result=asn1_der_coding(crl,"tbsCertList",der,der_len,errorDescription);
if(result!=ASN1_SUCCESS){
printf("\n'tbsCertList' encoding creation: ERROR\n");
return;
}
/* add the lines for the signature on der[0]..der[der_len-1]: result in str2 */
- result=asn1_write_value(crl,"crl1.signature",str2,46*8);
+ result=asn1_write_value(crl,"signature",str2,46*8);
/* Use the next 3 lines to visit the certificate */
/* printf("-----------------\n");
- asn1_visit_tree(crl,"crl1");
+ asn1_visit_tree(crl,"");
printf("-----------------\n"); */
- result=asn1_der_coding(crl,"crl1",der,der_len,errorDescription);
+ result=asn1_der_coding(crl,"",der,der_len,errorDescription);
if(result!=ASN1_SUCCESS){
printf("\n'crl1' encoding creation: ERROR\n");
return;
@@ -355,7 +349,7 @@ get_CRL(node_asn *cert_def,unsigned char *der,int der_len)
char errorDescription[MAX_ERROR_DESCRIPTION_SIZE];
- asn1_create_element(cert_def,"PKIX1Implicit88.CertificateList",&crl2,"crl2");
+ asn1_create_element(cert_def,"PKIX1Implicit88.CertificateList",&crl2);
result=asn1_der_decoding(&crl2,der,der_len,errorDescription);
@@ -366,30 +360,30 @@ get_CRL(node_asn *cert_def,unsigned char *der,int der_len)
/* issuer */
- get_Name_type(cert_def,crl2,"crl2.tbsCertList.issuer",str);
- printf("crl2:\nissuer =%s\n",str);
+ get_Name_type(cert_def,crl2,"tbsCertList.issuer",str);
+ printf("crl2:\nissuer: %s\n",str);
/* Verify sign */
len = sizeof(str)-1;
- result=asn1_read_value(crl2,"crl2.signatureAlgorithm.algorithm",str,&len);
+ result=asn1_read_value(crl2,"signatureAlgorithm.algorithm",str,&len);
result=asn1_read_value(cert_def,"PKIX1Implicit88.id-dsa-with-sha1",str2,&len);
if(!strcmp(str,str2)){ /* dsa-with-sha */
result=asn1_der_decoding_startEnd(crl2,der,der_len,
- "crl2.tbsCertList",&start,&end);
+ "tbsCertList",&start,&end);
/* add the lines to calculate the sha on der[start]..der[end] */
- result=asn1_read_value(crl2,"crl2.signature",str,&len);
+ result=asn1_read_value(crl2,"signature",str,&len);
/* compare the previous value to signature ( with issuer public key) */
}
/* Use the next 3 lines to visit the certificate */
/* printf("-----------------\n");
- asn1_visit_tree(crl2,"crl2");
+ asn1_visit_tree(crl2,"");
printf("-----------------\n"); */
diff --git a/src/asn1Coding.c b/src/asn1Coding.c
index 5d5f13d..2688332 100644
--- a/src/asn1Coding.c
+++ b/src/asn1Coding.c
@@ -31,6 +31,10 @@
#include <malloc.h>
#include <config.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
@@ -44,7 +48,7 @@ char help_man[] = "asn1Coding generates a DER encoding from a file\n"
" <file1> file with ASN1 definitions.\n"
" <file2> file with assignments.\n"
"\n"
-#ifdef HAVE_GETOPT_H
+#ifdef HAVE_GETOPT_LONG
"Operation modes:\n"
" -h, --help shows this message and exit.\n"
" -v, --version shows version information and exit.\n"
@@ -121,7 +125,7 @@ int
main(int argc,char *argv[])
{
-#ifdef HAVE_GETOPT_H
+#ifdef HAVE_GETOPT_LONG
static struct option long_options[] =
{
{"help", no_argument, 0, 'h'},
@@ -130,10 +134,10 @@ main(int argc,char *argv[])
{"output", required_argument, 0, 'o'},
{0, 0, 0, 0}
};
+ int option_index=0;
#endif
int option_result;
- int option_index = 0;
char *outputFileName=NULL;
char *inputFileAsnName=NULL;
char *inputFileAssignmentName=NULL;
@@ -146,7 +150,6 @@ main(int argc,char *argv[])
FILE *inputFile;
char varName[1024];
char value[1024];
- char structureName[1024];
unsigned char der[1024];
int der_len;
int k;
@@ -157,7 +160,7 @@ main(int argc,char *argv[])
while(1){
-#ifdef HAVE_GETOPT_H
+#ifdef HAVE_GETOPT_LONG
option_result=getopt_long(argc,argv,"hvco:",long_options,&option_index);
#else
option_result=getopt(argc,argv,"hvco:");
@@ -260,8 +263,7 @@ main(int argc,char *argv[])
while(readAssignment(inputFile,varName,value) == ASSIGNMENT_SUCCESS){
printf("var=%s, value=%s\n",varName,value);
if(structure==ASN1_TYPE_EMPTY){
- asn1_result=asn1_create_element(definitions,value,&structure,varName);
- strcpy(structureName,varName);
+ asn1_result=asn1_create_element(definitions,value,&structure);
}
else
asn1_result=asn1_write_value(structure,varName,value,0);
@@ -282,9 +284,9 @@ main(int argc,char *argv[])
fclose(inputFile);
printf("\n");
- asn1_print_structure(stdout,structure,structureName,ASN1_PRINT_NAME_TYPE_VALUE);
+ asn1_print_structure(stdout,structure,"",ASN1_PRINT_NAME_TYPE_VALUE);
- asn1_result=asn1_der_coding(structure,structureName,der,&der_len,
+ asn1_result=asn1_der_coding(structure,"",der,&der_len,
errorDescription);
printf("\nCoding: %s\n\n",libtasn1_strerror(asn1_result));
if(asn1_result!=ASN1_SUCCESS){
diff --git a/src/asn1Decoding.c b/src/asn1Decoding.c
index 928cdfb..780ab9c 100644
--- a/src/asn1Decoding.c
+++ b/src/asn1Decoding.c
@@ -31,6 +31,10 @@
#include <malloc.h>
#include <config.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
@@ -45,7 +49,7 @@ char help_man[] = "asn1Decoding generates an ASN1 type from a file\n"
" <file2> file with a DER coding.\n"
" <type> ASN1 type name\n"
"\n"
-#ifdef HAVE_GETOPT_H
+#ifdef HAVE_GETOPT_LONG
"Operation modes:\n"
" -h, --help shows this message and exit.\n"
" -v, --version shows version information and exit.\n"
@@ -67,7 +71,7 @@ int
main(int argc,char *argv[])
{
-#ifdef HAVE_GETOPT_H
+#ifdef HAVE_GETOPT_LONG
static struct option long_options[] =
{
{"help", no_argument, 0, 'h'},
@@ -75,14 +79,13 @@ main(int argc,char *argv[])
{"check", no_argument, 0, 'c'},
{0, 0, 0, 0}
};
+ int option_index = 0;
#endif
int option_result;
- int option_index = 0;
char *inputFileAsnName=NULL;
char *inputFileDerName=NULL;
char *typeName=NULL;
- char *varName=NULL;
int checkSyntaxOnly=0;
ASN1_TYPE definitions=ASN1_TYPE_EMPTY;
ASN1_TYPE structure=ASN1_TYPE_EMPTY;
@@ -91,7 +94,6 @@ main(int argc,char *argv[])
FILE *inputFile;
unsigned char der[1024];
int der_len=0;
- char *dot_p,*char_p;
opterr=0; /* disable error messages from getopt */
@@ -99,7 +101,7 @@ main(int argc,char *argv[])
while(1){
-#ifdef HAVE_GETOPT_H
+#ifdef HAVE_GETOPT_LONG
option_result=getopt_long(argc,argv,"hvc",long_options,&option_index);
#else
option_result=getopt(argc,argv,"hvc");
@@ -205,20 +207,9 @@ main(int argc,char *argv[])
der_len++;
fclose(inputFile);
-
- /* varName creation */
- dot_p=typeName;
- char_p=typeName;
- while((char_p=strchr(char_p,'.'))){
- char_p++;
- dot_p=char_p;
- }
-
- /* varName= inputFileName after the last '.' */
- varName=(char *)malloc(strlen(typeName)-(dot_p-typeName)+1);
- strcpy(varName,dot_p);
- asn1_result=asn1_create_element(definitions,typeName,&structure,varName);
+ asn1_result=asn1_create_element(definitions,typeName,&structure);
+
if(asn1_result != ASN1_SUCCESS){
printf("Structure creation: %s\n",libtasn1_strerror(asn1_result));
asn1_delete_structure(&definitions);
@@ -226,7 +217,6 @@ main(int argc,char *argv[])
free(inputFileAsnName);
free(inputFileDerName);
free(typeName);
- free(varName);
exit(1);
}
@@ -236,7 +226,7 @@ main(int argc,char *argv[])
printf("asn1Decoding: %s\n",errorDescription);
printf("\nDECODING RESULT:\n");
- asn1_print_structure(stdout,structure,varName,ASN1_PRINT_NAME_TYPE_VALUE);
+ asn1_print_structure(stdout,structure,"",ASN1_PRINT_NAME_TYPE_VALUE);
asn1_delete_structure(&definitions);
@@ -244,8 +234,7 @@ main(int argc,char *argv[])
free(inputFileAsnName);
free(inputFileDerName);
- free(typeName);
- free(varName);
+ free(typeName);
if(asn1_result != ASN1_SUCCESS)
exit(1);
diff --git a/src/asn1Parser.c b/src/asn1Parser.c
index 52f08bf..e071ad9 100644
--- a/src/asn1Parser.c
+++ b/src/asn1Parser.c
@@ -31,6 +31,10 @@
#include <malloc.h>
#include <config.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
@@ -42,7 +46,7 @@ char help_man[] = "asn1Parser reads files with ASN1 definitions and\n"
"\n"
"Usage: asn1Parser [options] file\n"
"\n"
-#ifdef HAVE_GETOPT_H
+#ifdef HAVE_GETOPT_LONG
"Operation modes:\n"
" -h, --help shows this message and exit\n"
" -v, --version shows version information and exit.\n"
@@ -70,7 +74,7 @@ int
main(int argc,char *argv[])
{
-#ifdef HAVE_GETOPT_H
+#ifdef HAVE_GETOPT_LONG
static struct option long_options[] =
{
{"help", no_argument, 0, 'h'},
@@ -80,10 +84,10 @@ main(int argc,char *argv[])
{"name", required_argument, 0, 'n'},
{0, 0, 0, 0}
};
+ int option_index = 0;
#endif
int option_result;
- int option_index = 0;
char *outputFileName=NULL;
char *inputFileName=NULL;
char *vectorName=NULL;
@@ -98,7 +102,7 @@ main(int argc,char *argv[])
while(1){
-#ifdef HAVE_GETOPT_H
+#ifdef HAVE_GETOPT_LONG
option_result=getopt_long(argc,argv,"hvco:n:",long_options,&option_index);
#else
option_result=getopt(argc,argv,"hvco:n:");
@@ -108,7 +112,7 @@ main(int argc,char *argv[])
switch(option_result){
case 0:
-#ifdef HAVE_GETOPT_H
+#ifdef HAVE_GETOPT_LONG
printf("option %s",long_options[option_index].name);
if(optarg) printf(" with arg %s",optarg);
printf("\n");