c-libp2p/include/libp2p/crypto/key.h

48 lines
1.6 KiB
C
Raw Permalink Normal View History

#pragma once
2017-07-20 20:03:11 +00:00
#include <stdlib.h>
/**
* Utilities for public keys
*/
enum KeyType { KEYTYPE_RSA, KEYTYPE_ED25519, KEYTYPE_INVALID };
struct PublicKey {
enum KeyType type;
unsigned char* data;
size_t data_size;
};
struct PrivateKey {
enum KeyType type;
unsigned char* data;
size_t data_size;
};
struct PublicKey* libp2p_crypto_public_key_new();
void libp2p_crypto_public_key_free(struct PublicKey* in);
struct PrivateKey* libp2p_crypto_private_key_new();
void libp2p_crypto_private_key_free(struct PrivateKey* in);
2017-02-13 22:41:31 +00:00
int libp2p_crypto_private_key_copy(const struct PrivateKey* source, struct PrivateKey* destination);
/**
* Unmarshal a public key from a protobuf
*/
int libp2p_crypto_public_key_protobuf_decode(unsigned char* buffer, size_t buffer_length, struct PublicKey** out);
2017-02-09 08:34:12 +00:00
size_t libp2p_crypto_public_key_protobuf_encode_size(const struct PublicKey* in);
int libp2p_crypto_public_key_protobuf_encode(const struct PublicKey* in, unsigned char* buffer, size_t max_buffer_length, size_t* bytes_written);
2017-02-13 22:41:31 +00:00
// private key
int libp2p_crypto_private_key_protobuf_decode(unsigned char* buffer, size_t buffer_length, struct PrivateKey** out);
2017-02-13 22:41:31 +00:00
size_t libp2p_crypto_private_key_protobuf_encode_size(const struct PrivateKey* in);
int libp2p_crypto_private_key_protobuf_encode(const struct PrivateKey* in, unsigned char* buffer, size_t max_buffer_length, size_t* bytes_written);
/**
* convert a public key into a peer id
* @param public_key the public key struct
* @param peer_id the results, in a null-terminated string
* @returns true(1) on success, otherwise false(0)
*/
int libp2p_crypto_public_key_to_peer_id(struct PublicKey* public_key, char** peer_id);