Guardtime KSI c SDK
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
27 extern "C" {
28 #endif
29 
30 #define KSI_DEFINE_FN_FROM_TLV(typ) \
31  \
39 int typ##_fromTlv(KSI_TLV *tlv, typ **o);
40 
41 #define KSI_DEFINE_FN_TO_TLV(typ) \
42  \
53 int 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) \
78 \
87  int typ##_serialize(const typ *t, unsigned char **raw, size_t *len);
88 
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 
156 
163  void KSI_Integer_free(KSI_Integer *o);
164 
177  char *KSI_Integer_toDateString(const KSI_Integer *o, char *buf, size_t buf_len);
178 
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 
250  int KSI_OctetString_equals(const KSI_OctetString *left, const KSI_OctetString *right);
251 
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_ */
#define KSI_uint64_t
Definition: types_base.h:105
int KSI_Integer_new(KSI_CTX *ctx, KSI_uint64_t value, KSI_Integer **o)
#define KSI_DEFINE_FN_TO_TLV(typ)
Definition: types_base.h:41
struct KSI_Integer_st KSI_Integer
Definition: types_base.h:140
char * KSI_Integer_toDateString(const KSI_Integer *o, char *buf, size_t buf_len)
int KSI_OctetString_equals(const KSI_OctetString *left, const KSI_OctetString *right)
#define KSI_DEFINE_FN_FROM_TLV(typ)
Definition: types_base.h:30
const char * KSI_Utf8String_cstr(const KSI_Utf8String *o)
int KSI_Integer_equals(const KSI_Integer *a, const KSI_Integer *b)
void KSI_Integer_free(KSI_Integer *o)
#define KSI_DEFINE_REF(typ)
Definition: types_base.h:56
KSI_uint64_t KSI_Integer_getUInt64(const KSI_Integer *o)
int KSI_Utf8StringNZ_toTlv(KSI_CTX *ctx, const KSI_Utf8String *o, unsigned tag, int isNonCritical, int isForward, KSI_TLV **tlv)
struct KSI_OctetString_st KSI_OctetString
Definition: types_base.h:145
void KSI_Utf8String_free(KSI_Utf8String *t)
int KSI_Utf8String_new(KSI_CTX *ctx, const char *str, size_t len, KSI_Utf8String **t)
int KSI_Integer_compare(const KSI_Integer *a, const KSI_Integer *b)
int KSI_OctetString_extract(const KSI_OctetString *t, const unsigned char **data, size_t *data_len)
size_t KSI_Utf8String_size(const KSI_Utf8String *t)
struct KSI_CTX_st KSI_CTX
Definition: types_base.h:124
void KSI_OctetString_free(KSI_OctetString *t)
struct KSI_TLV_st KSI_TLV
Definition: types_base.h:129
struct KSI_ERR_st KSI_ERR
Definition: types_base.h:134
int KSI_Integer_equalsUInt(const KSI_Integer *o, KSI_uint64_t i)
KSI_Utf8String KSI_Utf8StringNZ
Definition: types_base.h:155
struct KSI_Utf8String_st KSI_Utf8String
Definition: types_base.h:150
char * KSI_OctetString_toString(const KSI_OctetString *id, char separator, char *buf, size_t buf_len)
int KSI_OctetString_LegacyId_getUtf8String(const KSI_OctetString *id, KSI_Utf8String **str)
int(* KSI_LoggerCallback)(void *logCtx, int level, const char *message)
Definition: types_base.h:115
int KSI_OctetString_new(KSI_CTX *ctx, const unsigned char *data, size_t data_len, KSI_OctetString **t)
int KSI_Utf8StringNZ_fromTlv(KSI_TLV *tlv, KSI_Utf8String **o)