Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 #ifndef _BASIC_UTILS_H_
5 #define _BASIC_UTILS_H_
7 #include "seccomon.h"
8 #include "secitem.h"
9 #include "secoid.h"
10 #include "secoidt.h"
11 #include "secport.h"
12 #include "prerror.h"
13 #include "base64.h"
14 #include "secasn1.h"
15 #include "secder.h"
16 #include <stdio.h>
18 #ifdef SECUTIL_NEW
19 typedef int (*SECU_PPFunc)(PRFileDesc *out, SECItem *item,
20 char *msg, int level);
21 #else
22 typedef int (*SECU_PPFunc)(FILE *out, SECItem *item, char *msg, int level);
23 #endif
25 /* print out an error message */
26 extern void SECU_PrintError(const char *progName, const char *msg, ...);
28 /* print out a system error message */
29 extern void SECU_PrintSystemError(const char *progName, const char *msg, ...);
31 /* print a formatted error message */
32 extern void SECU_PrintErrMsg(FILE *out, int level, const char *progName,
33 const char *msg, ...);
35 /* Read the contents of a file into a SECItem */
36 extern SECStatus SECU_FileToItem(SECItem *dst, PRFileDesc *src);
37 extern SECStatus SECU_TextFileToItem(SECItem *dst, PRFileDesc *src);
39 /* Indent based on "level" */
40 extern void SECU_Indent(FILE *out, int level);
42 /* Print a newline to out */
43 extern void SECU_Newline(FILE *out);
45 /* Print integer value and hex */
46 extern void SECU_PrintInteger(FILE *out, const SECItem *i, const char *m,
47 int level);
49 /* Print SECItem as hex */
50 extern void SECU_PrintAsHex(FILE *out, const SECItem *i, const char *m,
51 int level);
53 /* dump a buffer in hex and ASCII */
54 extern void SECU_PrintBuf(FILE *out, const char *msg, const void *vp, int len);
56 #ifdef HAVE_EPV_TEMPLATE
57 /* Dump contents of private key */
58 extern int SECU_PrintPrivateKey(FILE *out, SECItem *der, char *m, int level);
59 #endif
61 /* Init PKCS11 stuff */
62 extern SECStatus SECU_PKCS11Init(PRBool readOnly);
64 /* Dump contents of signed data */
65 extern int SECU_PrintSignedData(FILE *out, SECItem *der, const char *m,
66 int level, SECU_PPFunc inner);
68 extern void SECU_PrintString(FILE *out, const SECItem *si, const char *m,
69 int level);
70 extern void SECU_PrintAny(FILE *out, const SECItem *i, const char *m, int level);
72 extern void SECU_PrintPRandOSError(const char *progName);
74 /* Caller ensures that dst is at least item->len*2+1 bytes long */
75 void
76 SECU_SECItemToHex(const SECItem * item, char * dst);
78 /* Requires 0x prefix. Case-insensitive. Will do in-place replacement if
79 * successful */
80 SECStatus
81 SECU_SECItemHexStringToBinary(SECItem* srcdest);
83 /*
84 *
85 * Utilities for parsing security tools command lines
86 *
87 */
89 /* A single command flag */
90 typedef struct {
91 char flag;
92 PRBool needsArg;
93 char *arg;
94 PRBool activated;
95 char *longform;
96 } secuCommandFlag;
98 /* A full array of command/option flags */
99 typedef struct
100 {
101 int numCommands;
102 int numOptions;
104 secuCommandFlag *commands;
105 secuCommandFlag *options;
106 } secuCommand;
108 /* fill the "arg" and "activated" fields for each flag */
109 SECStatus
110 SECU_ParseCommandLine(int argc, char **argv, char *progName,
111 const secuCommand *cmd);
112 char *
113 SECU_GetOptionArg(const secuCommand *cmd, int optionNum);
115 /*
116 *
117 * Error messaging
118 *
119 */
121 void printflags(char *trusts, unsigned int flags);
123 #if !defined(XP_UNIX) && !defined(XP_OS2)
124 extern int ffs(unsigned int i);
125 #endif
127 #include "secerr.h"
129 extern const char *hex;
130 extern const char printable[];
132 #endif /* _BASIC_UTILS_H_ */