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