tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

basicutil.h (3901B)


      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_
      6 
      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 "ecl-exp.h"
     17 #include <stdio.h>
     18 
     19 #ifdef SECUTIL_NEW
     20 typedef int (*SECU_PPFunc)(PRFileDesc *out, const SECItem *item,
     21                           const char *msg, int level);
     22 #else
     23 typedef int (*SECU_PPFunc)(FILE *out, const SECItem *item, const char *msg, int level);
     24 #endif
     25 
     26 /* print out an error message */
     27 extern void SECU_PrintError(const char *progName, const char *msg, ...);
     28 
     29 /* print out a system error message */
     30 extern void SECU_PrintSystemError(const char *progName, const char *msg, ...);
     31 
     32 /* print a formatted error message */
     33 extern void SECU_PrintErrMsg(FILE *out, int level, const char *progName,
     34                             const char *msg, ...);
     35 
     36 /* Read the contents of a file into a SECItem */
     37 extern SECStatus SECU_FileToItem(SECItem *dst, PRFileDesc *src);
     38 extern SECStatus SECU_TextFileToItem(SECItem *dst, PRFileDesc *src);
     39 
     40 /* Indent based on "level" */
     41 extern void SECU_Indent(FILE *out, int level);
     42 
     43 /* Print a newline to out */
     44 extern void SECU_Newline(FILE *out);
     45 
     46 /* Print integer value and hex */
     47 extern void SECU_PrintInteger(FILE *out, const SECItem *i, const char *m,
     48                              int level);
     49 
     50 /* Print SECItem as hex */
     51 extern void SECU_PrintAsHex(FILE *out, const SECItem *i, const char *m,
     52                            int level);
     53 
     54 /* dump a buffer in hex and ASCII */
     55 extern void SECU_PrintBuf(FILE *out, const char *msg, const void *vp, int len);
     56 
     57 /* Dump contents of private key */
     58 extern int SECU_PrintPrivateKey(FILE *out, SECItem *der, char *m, int level);
     59 
     60 /* Init PKCS11 stuff */
     61 extern SECStatus SECU_PKCS11Init(PRBool readOnly);
     62 
     63 /* Dump contents of signed data */
     64 extern int SECU_PrintSignedData(FILE *out, SECItem *der, const char *m,
     65                                int level, SECU_PPFunc inner);
     66 
     67 extern void SECU_PrintString(FILE *out, const SECItem *si, const char *m,
     68                             int level);
     69 extern void SECU_PrintAny(FILE *out, const SECItem *i, const char *m, int level);
     70 
     71 extern void SECU_PrintPRandOSError(const char *progName);
     72 
     73 /* Caller ensures that dst is at least item->len*2+1 bytes long */
     74 void
     75 SECU_SECItemToHex(const SECItem *item, char *dst);
     76 
     77 /* Requires 0x prefix. Case-insensitive. Will do in-place replacement if
     78 * successful */
     79 SECStatus
     80 SECU_SECItemHexStringToBinary(SECItem *srcdest);
     81 
     82 /*
     83 ** Read a hex string into a SecItem.
     84 */
     85 extern SECItem *SECU_HexString2SECItem(PLArenaPool *arena, SECItem *item,
     86                                       const char *str);
     87 
     88 extern SECStatus SECU_ecName2params(ECCurveName curve, SECItem *params);
     89 
     90 /*
     91 *
     92 *  Utilities for parsing security tools command lines
     93 *
     94 */
     95 
     96 /*  A single command flag  */
     97 typedef struct {
     98    char flag;
     99    PRBool needsArg;
    100    char *arg;
    101    PRBool activated;
    102    char *longform;
    103 } secuCommandFlag;
    104 
    105 /*  A full array of command/option flags  */
    106 typedef struct
    107 {
    108    int numCommands;
    109    int numOptions;
    110 
    111    secuCommandFlag *commands;
    112    secuCommandFlag *options;
    113 } secuCommand;
    114 
    115 /*  fill the "arg" and "activated" fields for each flag  */
    116 SECStatus
    117 SECU_ParseCommandLine(int argc, char **argv, char *progName,
    118                      const secuCommand *cmd);
    119 char *
    120 SECU_GetOptionArg(const secuCommand *cmd, int optionNum);
    121 
    122 /*
    123 *
    124 *  Error messaging
    125 *
    126 */
    127 
    128 void printflags(char *trusts, unsigned int flags);
    129 
    130 #if !defined(XP_UNIX)
    131 extern int ffs(unsigned int i);
    132 #endif
    133 
    134 #include "secerr.h"
    135 
    136 extern const char *hex;
    137 extern const char printable[];
    138 
    139 #endif /* _BASIC_UTILS_H_ */