1 /* Copyright 2015-2016 OpenMarket Ltd
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
21 /* Convenience macro for checking the return value of internal unpickling
22 * functions and returning early on failure. */
24 #define UNPICKLE_OK(x) do { if (!(x)) return NULL; } while(0)
27 /* Convenience macro for failing on corrupted pickles from public
28 * API unpickling functions. */
29 #define FAIL_ON_CORRUPTED_PICKLE(pos, session) \
32 session->last_error = OLM_CORRUPTED_PICKLE; \
41 struct _olm_ed25519_public_key;
42 struct _olm_ed25519_key_pair;
45 #define _olm_pickle_uint32_length(value) 4
46 uint8_t * _olm_pickle_uint32(uint8_t * pos, uint32_t value);
47 uint8_t const * _olm_unpickle_uint32(
48 uint8_t const * pos, uint8_t const * end,
53 #define _olm_pickle_bool_length(value) 1
54 uint8_t * _olm_pickle_bool(uint8_t * pos, int value);
55 uint8_t const * _olm_unpickle_bool(
56 uint8_t const * pos, uint8_t const * end,
60 #define _olm_pickle_bytes_length(bytes, bytes_length) (bytes_length)
61 uint8_t * _olm_pickle_bytes(uint8_t * pos, uint8_t const * bytes,
63 uint8_t const * _olm_unpickle_bytes(uint8_t const * pos, uint8_t const * end,
64 uint8_t * bytes, size_t bytes_length);
67 /** Get the number of bytes needed to pickle an ed25519 public key */
68 size_t _olm_pickle_ed25519_public_key_length(
69 const struct _olm_ed25519_public_key * value
72 /** Pickle the ed25519 public key. Returns a pointer to the next free space in
74 uint8_t * _olm_pickle_ed25519_public_key(
75 uint8_t *pos, const struct _olm_ed25519_public_key * value
78 /** Unpickle the ed25519 public key. Returns a pointer to the next item in the
79 * buffer on success, NULL on error. */
80 const uint8_t * _olm_unpickle_ed25519_public_key(
81 const uint8_t *pos, const uint8_t *end,
82 struct _olm_ed25519_public_key * value
85 /** Get the number of bytes needed to pickle an ed25519 key pair */
86 size_t _olm_pickle_ed25519_key_pair_length(
87 const struct _olm_ed25519_key_pair * value
90 /** Pickle the ed25519 key pair. Returns a pointer to the next free space in
92 uint8_t * _olm_pickle_ed25519_key_pair(
93 uint8_t *pos, const struct _olm_ed25519_key_pair * value
96 /** Unpickle the ed25519 key pair. Returns a pointer to the next item in the
97 * buffer on success, NULL on error. */
98 const uint8_t * _olm_unpickle_ed25519_key_pair(
99 const uint8_t *pos, const uint8_t *end,
100 struct _olm_ed25519_key_pair * value
107 #endif /* OLM_PICKLE_H */