1 /* misc.h - miscellaneous 2 * Copyright (C) 2002 Klarälvdalens Datakonsult AB 3 * 4 * This file is part of DirMngr. 5 * 6 * DirMngr is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * DirMngr is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 19 */ 20 21 #ifndef MISC_H 22 #define MISC_H 23 24 /* Convert hex encoded string back to binary. */ 25 size_t unhexify (unsigned char *result, const char *string); 26 27 /* Returns SHA1 hash of the data. */ 28 char* hashify_data( const char* data, size_t len ); 29 30 /* Returns data as a hex string. */ 31 char* hexify_data (const unsigned char* data, size_t len, int with_prefix); 32 33 /* Returns the serial number as a hex string. */ 34 char* serial_hex ( ksba_sexp_t serial ); 35 36 /* Take an S-Expression encoded blob and return a pointer to the 37 actual data as well as its length. */ 38 const unsigned char *serial_to_buffer (const ksba_sexp_t serial, 39 size_t *length); 40 41 /* Do an in-place percent unescaping of STRING. Returns STRING. */ 42 char *unpercent_string (char *string); 43 44 gpg_error_t canon_sexp_to_gcry (const unsigned char *canon, 45 gcry_sexp_t *r_sexp); 46 47 /* Return an allocated hex-string with the SHA-1 fingerprint of 48 CERT. */ 49 char *get_fingerprint_hexstring (ksba_cert_t cert); 50 /* Return an allocated hex-string with the SHA-1 fingerprint of 51 CERT. This version inserts the usual colons. */ 52 char *get_fingerprint_hexstring_colon (ksba_cert_t cert); 53 54 /* Log CERT in short format with s/n and issuer DN prefixed by TEXT. */ 55 void cert_log_name (const char *text, ksba_cert_t cert); 56 57 /* Log CERT in short format with the subject DN prefixed by TEXT. */ 58 void cert_log_subject (const char *text, ksba_cert_t cert); 59 60 /* Dump the serial number SERIALNO to the log stream. */ 61 void dump_serial (ksba_sexp_t serialno); 62 63 /* Dump STRING to the log file but choose the best readable 64 format. */ 65 void dump_string (const char *string); 66 67 /* Dump an KSBA cert object to the log stream. Prefix the output with 68 TEXT. This is used for debugging. */ 69 void dump_cert (const char *text, ksba_cert_t cert); 70 71 /* Callback to print infos about the TLS certificates. */ 72 void cert_log_cb (http_session_t sess, gpg_error_t err, 73 const char *hostname, const void **certs, size_t *certlens); 74 75 /* Return the host name and the port (0 if none was given) from the 76 URL. Return NULL on error or if host is not included in the 77 URL. */ 78 char *host_and_port_from_url (const char *url, int *port); 79 80 /* Create a KSBA reader object and connect it to the estream FP. */ 81 gpg_error_t create_estream_ksba_reader (ksba_reader_t *r_reader, estream_t fp); 82 83 /* Encode the binary data in {DATA,DATALEN} as ASCII-armored data and 84 stored it as a NUL-terminated string in *R_STRING. The caller is 85 responsible for freeing *R_STRING. */ 86 gpg_error_t armor_data (char **r_string, const void *data, size_t datalen); 87 88 /* Copy all data from IN to OUT. */ 89 gpg_error_t copy_stream (estream_t in, estream_t out); 90 91 #endif /* MISC_H */ 92