diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-01-04 14:24:24 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-01-04 14:24:24 +0000 |
commit | dc1565216a5d20ae0d75872151523252309a1292 (patch) | |
tree | d57454ba9a40386552179eddf60d28bd1e8f3d54 /nss/cmd/libpkix/sample_apps/dumpcert.c | |
parent | 26c046fbc57d53136b4fb3b5e0d18298318125d4 (diff) | |
download | nss-dc1565216a5d20ae0d75872151523252309a1292.tar.gz |
nss-3.28.1nss-3.28.1
Diffstat (limited to 'nss/cmd/libpkix/sample_apps/dumpcert.c')
-rw-r--r-- | nss/cmd/libpkix/sample_apps/dumpcert.c | 228 |
1 files changed, 113 insertions, 115 deletions
diff --git a/nss/cmd/libpkix/sample_apps/dumpcert.c b/nss/cmd/libpkix/sample_apps/dumpcert.c index 5535077..6ff5f83 100644 --- a/nss/cmd/libpkix/sample_apps/dumpcert.c +++ b/nss/cmd/libpkix/sample_apps/dumpcert.c @@ -23,162 +23,160 @@ static void *plContext = NULL; -static -void printUsage(void){ - (void) printf("\nUSAGE:\tdumpcert <certFile>\n"); - (void) printf("\tParses a certificate located at <certFile> " - "and displays it.\n"); +static void +printUsage(void) +{ + (void)printf("\nUSAGE:\tdumpcert <certFile>\n"); + (void)printf("\tParses a certificate located at <certFile> " + "and displays it.\n"); } -static -void printFailure(char *msg){ - (void) printf("FAILURE: %s\n", msg); +static void +printFailure(char *msg) +{ + (void)printf("FAILURE: %s\n", msg); } static PKIX_PL_Cert * createCert(char *inFileName) { - PKIX_PL_ByteArray *byteArray = NULL; - PKIX_PL_Cert *cert = NULL; - PKIX_Error *error = NULL; - PRFileDesc *inFile = NULL; - SECItem certDER; - void *buf = NULL; - PKIX_UInt32 len; - SECStatus rv = SECFailure; - - certDER.data = NULL; + PKIX_PL_ByteArray *byteArray = NULL; + PKIX_PL_Cert *cert = NULL; + PKIX_Error *error = NULL; + PRFileDesc *inFile = NULL; + SECItem certDER; + void *buf = NULL; + PKIX_UInt32 len; + SECStatus rv = SECFailure; + + certDER.data = NULL; + + inFile = PR_Open(inFileName, PR_RDONLY, 0); + + if (!inFile) { + printFailure("Unable to open cert file"); + goto cleanup; + } else { + rv = SECU_ReadDERFromFile(&certDER, inFile, PR_FALSE, PR_FALSE); + if (!rv) { + buf = (void *)certDER.data; + len = certDER.len; + + error = PKIX_PL_ByteArray_Create(buf, len, &byteArray, plContext); + + if (error) { + printFailure("PKIX_PL_ByteArray_Create failed"); + goto cleanup; + } - inFile = PR_Open(inFileName, PR_RDONLY, 0); + error = PKIX_PL_Cert_Create(byteArray, &cert, plContext); - if (!inFile){ - printFailure("Unable to open cert file"); + if (error) { + printFailure("PKIX_PL_Cert_Create failed"); goto cleanup; + } } else { - rv = SECU_ReadDERFromFile(&certDER, inFile, PR_FALSE, PR_FALSE); - if (!rv){ - buf = (void *)certDER.data; - len = certDER.len; - - error = PKIX_PL_ByteArray_Create - (buf, len, &byteArray, plContext); - - if (error){ - printFailure("PKIX_PL_ByteArray_Create failed"); - goto cleanup; - } - - error = PKIX_PL_Cert_Create - (byteArray, &cert, plContext); - - if (error){ - printFailure("PKIX_PL_Cert_Create failed"); - goto cleanup; - } - } else { - printFailure("Unable to read DER from cert file"); - goto cleanup; - } + printFailure("Unable to read DER from cert file"); + goto cleanup; } + } cleanup: - if (inFile){ - PR_Close(inFile); - } + if (inFile) { + PR_Close(inFile); + } - if (rv == SECSuccess){ - SECITEM_FreeItem(&certDER, PR_FALSE); - } + if (rv == SECSuccess) { + SECITEM_FreeItem(&certDER, PR_FALSE); + } - if (byteArray){ - PKIX_PL_Object_DecRef((PKIX_PL_Object *)(byteArray), plContext); - } + if (byteArray) { + PKIX_PL_Object_DecRef((PKIX_PL_Object *)(byteArray), plContext); + } - return (cert); + return (cert); } -int dumpcert(int argc, char *argv[]) +int +dumpcert(int argc, char *argv[]) { - PKIX_PL_String *string = NULL; - PKIX_PL_Cert *cert = NULL; - PKIX_Error *error = NULL; - char *ascii = NULL; - PKIX_UInt32 length = 0; - PKIX_UInt32 j = 0; - PKIX_Boolean useArenas = PKIX_FALSE; - PKIX_UInt32 actualMinorVersion; + PKIX_PL_String *string = NULL; + PKIX_PL_Cert *cert = NULL; + PKIX_Error *error = NULL; + char *ascii = NULL; + PKIX_UInt32 length = 0; + PKIX_UInt32 j = 0; + PKIX_Boolean useArenas = PKIX_FALSE; + PKIX_UInt32 actualMinorVersion; - PKIX_TEST_STD_VARS(); + PKIX_TEST_STD_VARS(); - if (argc == 1){ - printUsage(); - return (0); - } + if (argc == 1) { + printUsage(); + return (0); + } - useArenas = PKIX_TEST_ARENAS_ARG(argv[1]); + useArenas = PKIX_TEST_ARENAS_ARG(argv[1]); - PKIX_Initialize - (PKIX_TRUE, /* nssInitNeeded */ - useArenas, - PKIX_MAJOR_VERSION, - PKIX_MINOR_VERSION, - PKIX_MINOR_VERSION, - &actualMinorVersion, - &plContext); + PKIX_Initialize(PKIX_TRUE, /* nssInitNeeded */ + useArenas, + PKIX_MAJOR_VERSION, + PKIX_MINOR_VERSION, + PKIX_MINOR_VERSION, + &actualMinorVersion, + &plContext); - cert = createCert(argv[1+j]); + cert = createCert(argv[1 + j]); - if (cert){ + if (cert) { - error = PKIX_PL_Object_ToString - ((PKIX_PL_Object *)cert, &string, plContext); + error = PKIX_PL_Object_ToString((PKIX_PL_Object *)cert, &string, plContext); - if (error){ - printFailure("Unable to get string representation " - "of cert"); - goto cleanup; - } + if (error) { + printFailure("Unable to get string representation " + "of cert"); + goto cleanup; + } - error = PKIX_PL_String_GetEncoded - (string, - PKIX_ESCASCII, - (void **)&ascii, - &length, - plContext); + error = PKIX_PL_String_GetEncoded(string, + PKIX_ESCASCII, + (void **)&ascii, + &length, + plContext); - if (error || !ascii){ - printFailure("Unable to get ASCII encoding of string"); - goto cleanup; - } + if (error || !ascii) { + printFailure("Unable to get ASCII encoding of string"); + goto cleanup; + } - (void) printf("OUTPUT:\n%s\n", ascii); + (void)printf("OUTPUT:\n%s\n", ascii); - } else { - printFailure("Unable to create certificate"); - goto cleanup; - } + } else { + printFailure("Unable to create certificate"); + goto cleanup; + } cleanup: - if (cert){ - PKIX_PL_Object_DecRef((PKIX_PL_Object *)(cert), plContext); - } + if (cert) { + PKIX_PL_Object_DecRef((PKIX_PL_Object *)(cert), plContext); + } - if (string){ - PKIX_PL_Object_DecRef((PKIX_PL_Object *)(string), plContext); - } + if (string) { + PKIX_PL_Object_DecRef((PKIX_PL_Object *)(string), plContext); + } - if (ascii){ - PKIX_PL_Free((PKIX_PL_Object *)(ascii), plContext); - } + if (ascii) { + PKIX_PL_Free((PKIX_PL_Object *)(ascii), plContext); + } - PKIX_Shutdown(plContext); + PKIX_Shutdown(plContext); - PKIX_TEST_RETURN(); + PKIX_TEST_RETURN(); - endTests("DUMPCERT"); + endTests("DUMPCERT"); - return (0); + return (0); } |