📄 icutils.h
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
*/
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "vcert.h"
#include "stringutil.h"
#ifndef _ICUTILS_H_
#define _ICUTILS_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Converts buffer into 64 encoded buffer;
@param out - output 64 encoded buffer;
@param outLen - lenght of the output in bytes;
@param in - input buffer to be encoded;
@param inLen - length of the input in bytes;
@param oneLine - length on one line of input;
@param libCtx - mem context;
@return int - 0 success;
*/
int icBase64Encode (
unsigned char **out,
int *outLen,
unsigned char *in,
int inLen,
int oneLine,
VoltLibCtx *libCtx
);
/* Converts buffer from 64 encoded buffer;
@param out - output 64 decode buffer;
@param outLen - lenght of the output in bytes;
@param in - input buffer to be encoded;
@param inLen - length of the input in bytes;
@param oneLine - length on one line of output;
@param libCtx - mem context;
@return int - 0 success;
*/
int icBase64Decode (
unsigned char **out,
int *outLen,
unsigned char *in,
int inLen,
VoltLibCtx *libCtx
);
/* Given the cert "object", get the common name. This function will
* allocate the memory for the commonName (using the given libCtx) and
* will return it as a NULL-terminated string.
*/
int icGetCNFromCertAlloc (
VoltLibCtx *libCtx,
Asn1X509Cert *cert,
char **commonName
);
int icGetDistrictFromCN (
char *cn,
char **district1,
VoltLibCtx *libCtx
);
/* Build a URL from the prefix, server, and address. The format arg
* tells whether the three elements are complete or whether there is
* more information embedded in the final URL. The value of format must
* be one of the following.
* <pre>
* <code>
* VOLT_IC_URL
* VOLT_IC_URL_PARAMS
* VOLT_IC_URL_PARAMS_DEFAULT
* </code>
* </pre>
* <p>This function will allocate the space for the resulting URL and
* return that URL at the address given by result.
* <p>This function will return the string with a NULL-terminated
* character.
*/
int icBuildURLAlloc (
VoltLibCtx *libCtx,
unsigned int format,
char *prefix,
char *server,
char *address,
char **result
);
#define VOLT_IC_URL 1
#define VOLT_IC_URL_PARAMS 2
#define VOLT_IC_URL_PARAMS_MIDDLE "/params/"
#define VOLT_IC_URL_PARAMS_MIDDLE_LEN 8
#define VOLT_IC_URL_PARAMS_END ".pem"
#define VOLT_IC_URL_PARAMS_END_LEN 4
/* Build a new string from the input string with the XML metacharacters
* converted to the appropriate XML escape sequence. The characters that
* will be converted are: '<', '>', '&', '"', and '\''. It's up to the
* caller to free up the escaped string
*/
int icStringXMLEscapeAlloc(
VoltLibCtx* libCtx,
char* str,
char** escapedStr
);
/* Build a Server Request string. This will combine the requestData,
* authTokens, id (Base64 encoded), and cert request (Base64 encoded)
* into a single request string.
* <p>If the certReq64 arg is NULL, this will form a key only request.
* <p>This function will allocate the space for the resulting request
* and return that request at the address given by result.
* <p>This function will return the string with a NULL-terminated
* character.
*/
int icBuildServerRequestAlloc (
VoltLibCtx *libCtx,
char *requestData,
char *authTokens,
char *id64,
char *certReq64,
char **result
);
#define VOLT_IC_SERVER_REQ_PART_1 \
"<vs:request xmlns:vs=\"http://www.voltage.com/xmlns/vspv1\">\n" \
" <vs:header>\n" \
" <vs:client version=\""
#define VOLT_IC_SERVER_REQ_PART_1_LEN 97
#define VOLT_IC_SERVER_REQ_PART_2 "\"/>\n"
#define VOLT_IC_SERVER_REQ_PART_2_LEN 4
#define VOLT_IC_SERVER_REQ_PART_3 \
" </vs:header>\n" \
" <vs:body>\n" \
" <vs:keyRequest>\n" \
" <vs:id>\n "
#define VOLT_IC_SERVER_REQ_PART_3_LEN 69
#define VOLT_IC_SERVER_REQ_PART_4_REQ \
"\n </vs:id>\n" \
" </vs:keyRequest>\n" \
" <vs:pkcs10>\n "
#define VOLT_IC_SERVER_REQ_PART_4_REQ_LEN 59
#define VOLT_IC_SERVER_REQ_PART_4_NO_REQ \
"\n </vs:id>\n" \
" </vs:keyRequest>\n"
#define VOLT_IC_SERVER_REQ_PART_4_NO_REQ_LEN 37
#define VOLT_IC_SERVER_REQ_PART_5_REQ \
"\n </vs:pkcs10>\n" \
" </vs:body>\n" \
"</vs:request>\n"
#define VOLT_IC_SERVER_REQ_PART_5_REQ_LEN 45
#define VOLT_IC_SERVER_REQ_PART_5_NO_REQ \
" </vs:body>\n" \
"</vs:request>\n"
#define VOLT_IC_SERVER_REQ_PART_5_NO_REQ_LEN 27
/* Returns 0, always succeeds.
* This function does no arg checking, it is the responsibility of the
* caller to pass in valid input and output buffers.
*/
int icSafeStrncpy (
char *dest,
char *src,
int len,
VoltLibCtx *libCtx
);
/* Replaces portions of the string.
* The string at *str is the input string.
* The function might have to "reallocate" if the replacement string is
* longer than the original, so the address at *str might be different.
* Returns 0 for success, nonzero error code.
*/
int icStrrepl (
char **str,
char *find,
char *replace,
VoltLibCtx *libCtx
);
int icStrprependalloc (
char **str,
char *pre,
VoltLibCtx *libCtx
);
int icStrcatalloc (
char **str,
char *cat,
VoltLibCtx *libCtx
);
int icStringlower (
char *str,
VoltLibCtx *libCtx
);
int icIsStringlower (
char *str,
VoltLibCtx *libCtx
);
int icTrim (
char *str,
VoltLibCtx *libCtx
);
int icXstricmpsafe (
char *pat,
char *str,
VoltLibCtx *libCtx
);
#ifdef __cplusplus
}
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -