Guardtime KSI c SDK
Loading...
Searching...
No Matches
types_base.h
Go to the documentation of this file.
1/*
2 * Copyright 2013-2015 Guardtime, Inc.
3 *
4 * This file is part of the Guardtime client SDK.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License").
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES, CONDITIONS, OR OTHER LICENSES OF ANY KIND, either
13 * express or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
15 * "Guardtime" and "KSI" are trademarks or registered trademarks of
16 * Guardtime, Inc., and no license to trademarks is granted; Guardtime
17 * reserves and retains all trademark rights.
18 */
19
20#ifndef TYPES_BASE_H_
21#define TYPES_BASE_H_
22
23#include <stdint.h>
24#include "list.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#define KSI_DEFINE_FN_FROM_TLV(typ) \
31
33
34 \param[in] tlv Pointer to #KSI_TLV.
35 \param[out] o Pointer to receiving pointer.
36 \return status code (\c KSI_OK, when operation succeeded, otherwise an error code).
37 \see \ref typ##_fromTlv
38*/ \
39int typ##_fromTlv(KSI_TLV *tlv, typ **o);
40
41#define KSI_DEFINE_FN_TO_TLV(typ) \
42
43 Function to convert a \ref typ to a plain #KSI_TLV object.
44 \param[in] ctx KSI context.
45 \param[in] o Pointer to \ref typ
46 \param[in] tag Tag value of the #KSI_TLV
47 \param[in] isNonCritical Flag is-non-critical.
48 \param[in] isForward Flag is-forward.
49 \param[out] tlv Pointer to the receiving pointer.
50 \return status code (\c KSI_OK, when operation succeeded, otherwise an error code).
51 \see \ref typ##_fromTlv, \ref KSI_TLV_free
52*/ \
53int typ##_toTlv(KSI_CTX *ctx, const typ *o, unsigned tag, int isNonCritical, int isForward, KSI_TLV **tlv);
54
55
56#define KSI_DEFINE_REF(typ) \
57 \
63 typ *typ##_ref(typ *o)
64
65#define KSI_DEFINE_OBJECT_PARSE(typ) \
66 \
75 int typ##_parse(KSI_CTX *ctx, const unsigned char *raw, size_t len, typ **t);
76
77#define KSI_DEFINE_OBJECT_SERIALIZE(typ) \
87 int typ##_serialize(const typ *t, unsigned char **raw, size_t *len);
89#define KSI_DEFINE_WRITE_BYTES(typ) \
90\
99 int typ##_writeBytes(typ *o, unsigned char *buf, size_t buf_size, size_t *buf_len, int opt)
100
105 #define KSI_uint64_t uint64_t
106 #define KSI_DEFINE_GET_CTX(type) KSI_CTX *type##_getCtx(const type *o);
107
115 typedef int (*KSI_LoggerCallback)(void *logCtx, int level, const char *message);
116
124 typedef struct KSI_CTX_st KSI_CTX;
125
129 typedef struct KSI_TLV_st KSI_TLV;
130
134 typedef struct KSI_ERR_st KSI_ERR;
135
140 typedef struct KSI_Integer_st KSI_Integer;
141
145 typedef struct KSI_OctetString_st KSI_OctetString;
146
150 typedef struct KSI_Utf8String_st KSI_Utf8String;
151
164
177 char *KSI_Integer_toDateString(const KSI_Integer *o, char *buf, size_t buf_len);
185
193 int KSI_Integer_new(KSI_CTX *ctx, KSI_uint64_t value, KSI_Integer **o);
194
202 int KSI_Integer_equals(const KSI_Integer *a, const KSI_Integer *b);
203
211 int KSI_Integer_compare(const KSI_Integer *a, const KSI_Integer *b);
212
222
223
227
233
241 int KSI_OctetString_new(KSI_CTX *ctx, const unsigned char *data, size_t data_len, KSI_OctetString **t);
242 int KSI_OctetString_extract(const KSI_OctetString *t, const unsigned char **data, size_t *data_len);
243
255
256 char* KSI_OctetString_toString(const KSI_OctetString *id, char separator, char *buf, size_t buf_len);
257
258 /*
259 * KSI_Utf8String
260 */
261
267
277 int KSI_Utf8String_new(KSI_CTX *ctx, const char *str, size_t len, KSI_Utf8String **t);
278
284 size_t KSI_Utf8String_size(const KSI_Utf8String *t);
285
293 const char *KSI_Utf8String_cstr(const KSI_Utf8String *o);
294
298
307
319 int KSI_Utf8StringNZ_toTlv(KSI_CTX *ctx, const KSI_Utf8String *o, unsigned tag, int isNonCritical, int isForward, KSI_TLV **tlv);
320
321
322 /*
323 * Helper functions
324 */
325
334
335
339#ifdef __cplusplus
340}
341#endif
342
343#endif /* TYPES_BASE_H_ */
int KSI_Utf8String_new(KSI_CTX *ctx, const char *str, size_t len, KSI_Utf8String **t)
struct KSI_Integer_st KSI_Integer
Definition types_base.h:94
KSI_Utf8String KSI_Utf8StringNZ
Definition types_base.h:109
int KSI_Integer_equalsUInt(const KSI_Integer *o, KSI_uint64_t i)
struct KSI_TLV_st KSI_TLV
Definition types_base.h:83
int KSI_OctetString_LegacyId_getUtf8String(const KSI_OctetString *id, KSI_Utf8String **str)
int KSI_Utf8StringNZ_toTlv(KSI_CTX *ctx, const KSI_Utf8String *o, unsigned tag, int isNonCritical, int isForward, KSI_TLV **tlv)
void KSI_OctetString_free(KSI_OctetString *t)
struct KSI_OctetString_st KSI_OctetString
Definition types_base.h:99
void KSI_Utf8String_free(KSI_Utf8String *t)
struct KSI_ERR_st KSI_ERR
Definition types_base.h:88
struct KSI_CTX_st KSI_CTX
Definition types_base.h:78
int KSI_Utf8StringNZ_fromTlv(KSI_TLV *tlv, KSI_Utf8String **o)
char * KSI_Integer_toDateString(const KSI_Integer *o, char *buf, size_t buf_len)
int KSI_OctetString_extract(const KSI_OctetString *t, const unsigned char **data, size_t *data_len)
int(* KSI_LoggerCallback)(void *logCtx, int level, const char *message)
Definition types_base.h:69
#define KSI_uint64_t
Definition types_base.h:59
int KSI_Integer_equals(const KSI_Integer *a, const KSI_Integer *b)
struct KSI_Utf8String_st KSI_Utf8String
Definition types_base.h:104
KSI_uint64_t KSI_Integer_getUInt64(const KSI_Integer *o)
int KSI_Integer_compare(const KSI_Integer *a, const KSI_Integer *b)
size_t KSI_Utf8String_size(const KSI_Utf8String *t)
int KSI_OctetString_equals(const KSI_OctetString *left, const KSI_OctetString *right)
char * KSI_OctetString_toString(const KSI_OctetString *id, char separator, char *buf, size_t buf_len)
int KSI_OctetString_new(KSI_CTX *ctx, const unsigned char *data, size_t data_len, KSI_OctetString **t)
void KSI_Integer_free(KSI_Integer *o)
const char * KSI_Utf8String_cstr(const KSI_Utf8String *o)
int KSI_Integer_new(KSI_CTX *ctx, KSI_uint64_t value, KSI_Integer **o)
#define KSI_DEFINE_REF(typ)
Definition types_base.h:39
#define KSI_DEFINE_FN_FROM_TLV(typ)
Definition types_base.h:30
#define KSI_DEFINE_FN_TO_TLV(typ)
Definition types_base.h:34