michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef _BASIC_UTILS_H_ michael@0: #define _BASIC_UTILS_H_ michael@0: michael@0: #include "seccomon.h" michael@0: #include "secitem.h" michael@0: #include "secoid.h" michael@0: #include "secoidt.h" michael@0: #include "secport.h" michael@0: #include "prerror.h" michael@0: #include "base64.h" michael@0: #include "secasn1.h" michael@0: #include "secder.h" michael@0: #include michael@0: michael@0: #ifdef SECUTIL_NEW michael@0: typedef int (*SECU_PPFunc)(PRFileDesc *out, SECItem *item, michael@0: char *msg, int level); michael@0: #else michael@0: typedef int (*SECU_PPFunc)(FILE *out, SECItem *item, char *msg, int level); michael@0: #endif michael@0: michael@0: /* print out an error message */ michael@0: extern void SECU_PrintError(const char *progName, const char *msg, ...); michael@0: michael@0: /* print out a system error message */ michael@0: extern void SECU_PrintSystemError(const char *progName, const char *msg, ...); michael@0: michael@0: /* print a formatted error message */ michael@0: extern void SECU_PrintErrMsg(FILE *out, int level, const char *progName, michael@0: const char *msg, ...); michael@0: michael@0: /* Read the contents of a file into a SECItem */ michael@0: extern SECStatus SECU_FileToItem(SECItem *dst, PRFileDesc *src); michael@0: extern SECStatus SECU_TextFileToItem(SECItem *dst, PRFileDesc *src); michael@0: michael@0: /* Indent based on "level" */ michael@0: extern void SECU_Indent(FILE *out, int level); michael@0: michael@0: /* Print a newline to out */ michael@0: extern void SECU_Newline(FILE *out); michael@0: michael@0: /* Print integer value and hex */ michael@0: extern void SECU_PrintInteger(FILE *out, const SECItem *i, const char *m, michael@0: int level); michael@0: michael@0: /* Print SECItem as hex */ michael@0: extern void SECU_PrintAsHex(FILE *out, const SECItem *i, const char *m, michael@0: int level); michael@0: michael@0: /* dump a buffer in hex and ASCII */ michael@0: extern void SECU_PrintBuf(FILE *out, const char *msg, const void *vp, int len); michael@0: michael@0: #ifdef HAVE_EPV_TEMPLATE michael@0: /* Dump contents of private key */ michael@0: extern int SECU_PrintPrivateKey(FILE *out, SECItem *der, char *m, int level); michael@0: #endif michael@0: michael@0: /* Init PKCS11 stuff */ michael@0: extern SECStatus SECU_PKCS11Init(PRBool readOnly); michael@0: michael@0: /* Dump contents of signed data */ michael@0: extern int SECU_PrintSignedData(FILE *out, SECItem *der, const char *m, michael@0: int level, SECU_PPFunc inner); michael@0: michael@0: extern void SECU_PrintString(FILE *out, const SECItem *si, const char *m, michael@0: int level); michael@0: extern void SECU_PrintAny(FILE *out, const SECItem *i, const char *m, int level); michael@0: michael@0: extern void SECU_PrintPRandOSError(const char *progName); michael@0: michael@0: /* Caller ensures that dst is at least item->len*2+1 bytes long */ michael@0: void michael@0: SECU_SECItemToHex(const SECItem * item, char * dst); michael@0: michael@0: /* Requires 0x prefix. Case-insensitive. Will do in-place replacement if michael@0: * successful */ michael@0: SECStatus michael@0: SECU_SECItemHexStringToBinary(SECItem* srcdest); michael@0: michael@0: /* michael@0: * michael@0: * Utilities for parsing security tools command lines michael@0: * michael@0: */ michael@0: michael@0: /* A single command flag */ michael@0: typedef struct { michael@0: char flag; michael@0: PRBool needsArg; michael@0: char *arg; michael@0: PRBool activated; michael@0: char *longform; michael@0: } secuCommandFlag; michael@0: michael@0: /* A full array of command/option flags */ michael@0: typedef struct michael@0: { michael@0: int numCommands; michael@0: int numOptions; michael@0: michael@0: secuCommandFlag *commands; michael@0: secuCommandFlag *options; michael@0: } secuCommand; michael@0: michael@0: /* fill the "arg" and "activated" fields for each flag */ michael@0: SECStatus michael@0: SECU_ParseCommandLine(int argc, char **argv, char *progName, michael@0: const secuCommand *cmd); michael@0: char * michael@0: SECU_GetOptionArg(const secuCommand *cmd, int optionNum); michael@0: michael@0: /* michael@0: * michael@0: * Error messaging michael@0: * michael@0: */ michael@0: michael@0: void printflags(char *trusts, unsigned int flags); michael@0: michael@0: #if !defined(XP_UNIX) && !defined(XP_OS2) michael@0: extern int ffs(unsigned int i); michael@0: #endif michael@0: michael@0: #include "secerr.h" michael@0: michael@0: extern const char *hex; michael@0: extern const char printable[]; michael@0: michael@0: #endif /* _BASIC_UTILS_H_ */