summaryrefslogtreecommitdiff
path: root/usr/src/lib/libkmsagent/common/KMSAgentStringUtilities.h
blob: 1705a266ff4f77bcff6f6e1a1fea41a21c01d35f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
 */

/**
 * @file KMSAgentStringUtilities.h
 */

#ifndef KMSAgentStringUtilities_h
#define KMSAgentStringUtilities_h

#ifdef WIN32
#pragma warning(disable: 4786)
#endif

#include <stdio.h>

#include "SYSCommon.h"

#ifdef __cplusplus
extern "C" {
#endif

//
// Functions for conversions between integers and strings.
//

/*---------------------------------------------------------------------------*/
/**
 *  Converts a UTF8 string to an int64.
 *
 *  @param   i_sNumber: A string representation of the number to convert.
 *  @return  The integer the input string represented.
 */
/*---------------------------------------------------------------------------*/
 int64 UTF8ToInt64( const char* i_sNumber );

/**
 * Formats an int64 into a UTF8 string.
 *
 * A note on padding: If i_bPad is true, the string will be padded to the 
 * maximum size necessary to hold a an int64 representation. For decimal this 
 * is 19, for hex it is 16.
 *
 *  @param i_iNumber The number to format.
 *  @param i_bPad If true, the string will be padded with zeroes. (See note above.)
 *  @param i_bHex Indicates whether the string format should be a hexadecimal 
 *    representation of the integer (true) or a decimal representation (false).
 *  @param o_psUTF8 the string representation of the integer
 *
 *  @return  void
 */
void Int64ToUTF8(char* const o_psUTF8, 
                 int64 i_iNumber, 
                 int i_bPad, 
                 int i_bHex );

//
// Functions for converting between binary buffer and hex string
//

/*--------------------------------------------------------------------------*/
/**
 *  Converts a UTF8 hex string to its binary representation.
 *
 *  If o_pBinaryBuffer is null, the function will return the required size.
 *  (The required size is always strlen(i_sHexString)/2.)
 *
 *  @param   i_sHexString:     The hex string to convert.
 *  @param   o_pBinaryBuffer:  The buffer in which to put the binary
 *     representation of the hex string. If this is null, the function
 *     returns the required size.
 *     If this is not null, it must be large enough to hold binary conversion.
 *
 *  @return The number of bytes put into o_pBinaryBuffer (or the number of bytes
 *     required, if o_pBinaryBuffer was null).
 */
/*---------------------------------------------------------------------------*/
int ConvertUTF8HexStringToBinary(
   const char* i_sHexString,
   unsigned char* o_pBinaryBuffer);

/**
 * Converts a binary buffer to its UTF8 hex string representation.
 * 
 *  @param i_pBinaryBuffer: The binary buffer to convert.
 *  @param i_iBinaryBufferSize: The size of i_pBinaryBuffer;
 *  @param o_sHexString The hex string representation of the
 *                      binary buffer which should be at least
 *                      (i_iBinaryBufferSize * 2) + 1 characters long
 */
void ConvertBinaryToUTF8HexString(
                             char* const                o_sHexString, 
                             const unsigned char* const i_pBinaryBuffer, 
                             int                        i_iBinaryBufferSize );

//
// Functions for date strings
//

/**
 *  populates o_psDateTimeISO8601UTC with a null terminated ISO 8601
 *  formatted timestamp string from the current UTC time of the
 *  system.  The timestamp length will be restricted to i_iLength-1
 *  characters.
 */
void GetCurrentDateTimeISO8601UTC(char* const o_psDateTimeISO8601UTC,
                                  int i_iLength);

#ifdef __cplusplus
}
#endif

#endif //KMSAgentStringUtilities_h