1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/cmd/lib/basicutil.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,132 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 +#ifndef _BASIC_UTILS_H_ 1.8 +#define _BASIC_UTILS_H_ 1.9 + 1.10 +#include "seccomon.h" 1.11 +#include "secitem.h" 1.12 +#include "secoid.h" 1.13 +#include "secoidt.h" 1.14 +#include "secport.h" 1.15 +#include "prerror.h" 1.16 +#include "base64.h" 1.17 +#include "secasn1.h" 1.18 +#include "secder.h" 1.19 +#include <stdio.h> 1.20 + 1.21 +#ifdef SECUTIL_NEW 1.22 +typedef int (*SECU_PPFunc)(PRFileDesc *out, SECItem *item, 1.23 + char *msg, int level); 1.24 +#else 1.25 +typedef int (*SECU_PPFunc)(FILE *out, SECItem *item, char *msg, int level); 1.26 +#endif 1.27 + 1.28 +/* print out an error message */ 1.29 +extern void SECU_PrintError(const char *progName, const char *msg, ...); 1.30 + 1.31 +/* print out a system error message */ 1.32 +extern void SECU_PrintSystemError(const char *progName, const char *msg, ...); 1.33 + 1.34 +/* print a formatted error message */ 1.35 +extern void SECU_PrintErrMsg(FILE *out, int level, const char *progName, 1.36 + const char *msg, ...); 1.37 + 1.38 +/* Read the contents of a file into a SECItem */ 1.39 +extern SECStatus SECU_FileToItem(SECItem *dst, PRFileDesc *src); 1.40 +extern SECStatus SECU_TextFileToItem(SECItem *dst, PRFileDesc *src); 1.41 + 1.42 +/* Indent based on "level" */ 1.43 +extern void SECU_Indent(FILE *out, int level); 1.44 + 1.45 +/* Print a newline to out */ 1.46 +extern void SECU_Newline(FILE *out); 1.47 + 1.48 +/* Print integer value and hex */ 1.49 +extern void SECU_PrintInteger(FILE *out, const SECItem *i, const char *m, 1.50 + int level); 1.51 + 1.52 +/* Print SECItem as hex */ 1.53 +extern void SECU_PrintAsHex(FILE *out, const SECItem *i, const char *m, 1.54 + int level); 1.55 + 1.56 +/* dump a buffer in hex and ASCII */ 1.57 +extern void SECU_PrintBuf(FILE *out, const char *msg, const void *vp, int len); 1.58 + 1.59 +#ifdef HAVE_EPV_TEMPLATE 1.60 +/* Dump contents of private key */ 1.61 +extern int SECU_PrintPrivateKey(FILE *out, SECItem *der, char *m, int level); 1.62 +#endif 1.63 + 1.64 +/* Init PKCS11 stuff */ 1.65 +extern SECStatus SECU_PKCS11Init(PRBool readOnly); 1.66 + 1.67 +/* Dump contents of signed data */ 1.68 +extern int SECU_PrintSignedData(FILE *out, SECItem *der, const char *m, 1.69 + int level, SECU_PPFunc inner); 1.70 + 1.71 +extern void SECU_PrintString(FILE *out, const SECItem *si, const char *m, 1.72 + int level); 1.73 +extern void SECU_PrintAny(FILE *out, const SECItem *i, const char *m, int level); 1.74 + 1.75 +extern void SECU_PrintPRandOSError(const char *progName); 1.76 + 1.77 +/* Caller ensures that dst is at least item->len*2+1 bytes long */ 1.78 +void 1.79 +SECU_SECItemToHex(const SECItem * item, char * dst); 1.80 + 1.81 +/* Requires 0x prefix. Case-insensitive. Will do in-place replacement if 1.82 + * successful */ 1.83 +SECStatus 1.84 +SECU_SECItemHexStringToBinary(SECItem* srcdest); 1.85 + 1.86 +/* 1.87 + * 1.88 + * Utilities for parsing security tools command lines 1.89 + * 1.90 + */ 1.91 + 1.92 +/* A single command flag */ 1.93 +typedef struct { 1.94 + char flag; 1.95 + PRBool needsArg; 1.96 + char *arg; 1.97 + PRBool activated; 1.98 + char *longform; 1.99 +} secuCommandFlag; 1.100 + 1.101 +/* A full array of command/option flags */ 1.102 +typedef struct 1.103 +{ 1.104 + int numCommands; 1.105 + int numOptions; 1.106 + 1.107 + secuCommandFlag *commands; 1.108 + secuCommandFlag *options; 1.109 +} secuCommand; 1.110 + 1.111 +/* fill the "arg" and "activated" fields for each flag */ 1.112 +SECStatus 1.113 +SECU_ParseCommandLine(int argc, char **argv, char *progName, 1.114 + const secuCommand *cmd); 1.115 +char * 1.116 +SECU_GetOptionArg(const secuCommand *cmd, int optionNum); 1.117 + 1.118 +/* 1.119 + * 1.120 + * Error messaging 1.121 + * 1.122 + */ 1.123 + 1.124 +void printflags(char *trusts, unsigned int flags); 1.125 + 1.126 +#if !defined(XP_UNIX) && !defined(XP_OS2) 1.127 +extern int ffs(unsigned int i); 1.128 +#endif 1.129 + 1.130 +#include "secerr.h" 1.131 + 1.132 +extern const char *hex; 1.133 +extern const char printable[]; 1.134 + 1.135 +#endif /* _BASIC_UTILS_H_ */