5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2005 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
22 /* Encodes Public Key Payload for transmitting public keys and certificates. */
24 SilcBuffer silc_public_key_payload_encode(SilcPublicKey public_key)
34 type = silc_pkcs_get_type(public_key);
35 pk = silc_pkcs_public_key_encode(public_key, &pk_len);
39 buffer = silc_buffer_alloc_size(4 + pk_len);
45 if (silc_buffer_format(buffer,
46 SILC_STR_UI_SHORT(pk_len),
47 SILC_STR_UI_SHORT(type),
48 SILC_STR_DATA(pk, pk_len),
50 silc_buffer_free(buffer);
59 /* Decodes public key payload and returns allocated public key */
61 SilcBool silc_public_key_payload_decode(unsigned char *data,
63 SilcPublicKey *public_key)
66 SilcUInt16 pk_len, pk_type;
73 silc_buffer_set(&buf, data, data_len);
74 ret = silc_buffer_unformat(&buf,
76 SILC_STR_UI_SHORT(&pk_len),
77 SILC_STR_UI_SHORT(&pk_type),
79 if (ret < 0 || pk_len > data_len - 4)
82 if (pk_type < SILC_PKCS_SILC || pk_type > SILC_PKCS_SPKI)
85 ret = silc_buffer_unformat(&buf,
86 SILC_STR_DATA(&pk, pk_len),
91 return silc_pkcs_public_key_alloc((SilcPKCSType)pk_type,
92 pk, pk_len, public_key);