The following types can be serialized and deserialized:
HVE_t QEDPrivateKey_t QEDPublicKey_t QEDToken_t QEDEncryption_t QEDMessageKey_tFunctions to serialize type HVE_t:
- int byte_count_HVE(HVE_t *HVE);
-
Returns the length in bytes the variable HVE will take to represent.
- int serialize_HVE(HVE_t *HVE, unsigned char *data);
-
Converts HVE to byte, writing the result in the buffer data. The number of bytes it will write can be determined from calling
byte_count_HVE(). It Returns the number of bytes written.
- int deserialize_HVE(HVE_t *HVE, unsigned char *data);
-
Reads HVE from the buffer data, and returns the number of bytes read.
Functions to serialize QEDPrivateKey_t:
- int byte_count_PrivateKey(QEDPrivateKey_t *PrivKey);
- int serialize_PrivateKey(QEDPrivateKey_t *PrivKey, unsigned char *data);
- int deserialize_PrivateKey(QEDPrivateKey_t *PrivKey, unsigned char *data);
- int byte_count_PublicKey(QEDPublicKey_t *PubKey);
- int serialize_PublicKey(QEDPublicKey_t *PubKey, unsigned char *data);
- int deserialize_PublicKey(QEDPublicKey_t *PubKey, unsigned char *data);
- int byte_count_GenToken(QEDToken_t *Tok);
- int serialize_GenToken(QEDToken_t *Tok, unsigned char *data);
- int deserialize_GenToken(QEDToken_t *Tok, unsigned char *data);
- int byte_count_EncToken(QEDEncryption_t *Encr);
- int serialize_EncToken(QEDEncryption_t *Encr, unsigned char *data);
- int deserialize_EncToken(QEDEncryption_t *Encr, unsigned char *data);
- int byte_count_MsgKey(QEDMessageKey_t *Msg);
- int serialize_MsgKey(QEDMessageKey_t *Msg, unsigned char *data);
- int deserialize_MsgKey(QEDMessageKey_t *Msg, unsigned char *data);
You can also read/write these types to a file, using writeFile and readFile:
int readFile(const char *fileName, unsigned char **bytes, unsigned *numBytes); int writeFile(const char *fileName, const unsigned char *bytes, unsigned numBytes);Here is an example of serializing a QEDPublicKey_t type and exporting it to a file:
QEDPublicKey_t PubKey; uint8_t *bytes; size_t bytes_len; bytes_len = byte_count_PubKey(&PubKey); bytes = calloc(sizeof(uint8_t), bytes_len); bytes_len = serialize_PubKey(&PubKey, bytes); if(writeFile(PubKeyFile, bytes, bytes_len)) { printf("Cannot export public key to file %s\n", PubKeyFile); exit(1); } free(bytes);And here is an example of importing data and deserializing it to a QEDPublicKey_t type:
QEDPublicKey_t PubKey; uint8_t *bytes; size_t bytes_len; if(readFile(PubKeyFile, &bytes, &bytes_len)) { printf("Cannot import public key from file %s\n", PubKeyFile); } bytes_len = deserialize_PubKey(&PubKey, bytes); free(bytes);