tagion_decrypt_devicepin

Decrypt and create a securenet from a devicepin and pincode

extern (C)
int
tagion_decrypt_devicepin
(
const(char*) pin_ptr
,
const(size_t) pin_len
,
uint8_t* devicepin_ptr
,,)

Parameters

pin_ptr const(char*)

Pointer to the pincode

pin_len const(size_t)

Length of the pincode

devicepin_ptr uint8_t*

Pointer to the device pin document

devicepin_len size_t

Length of the device pin document

out_securenet securenet_t*

The allocated securenet

Return Value

Type: int

Examples

Decrypt a devicepin

/// create key-pair with devicepin
import tagion.hibon.HiBONRecord;
import std.format;
securenet_t my_keypair;
string my_mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon";
string pincode = "1234";

uint8_t* device_buf;
size_t device_len;
int error_code = tagion_generate_keypair(&my_mnemonic[0], my_mnemonic.length, null, 0, &my_keypair, &pincode[0], pincode.length, &device_buf, &device_len);
assert(error_code == ErrorCode.none);

const _device_buf = device_buf[0..device_len].idup;
const device_doc = Document(_device_buf);
assert(device_doc.isRecord!DevicePIN, format("the doc was not of type %s", DevicePIN.stringof));

/// decrypt the devicepin
securenet_t other_securenet;
error_code = tagion_decrypt_devicepin(&pincode[0], pincode.length, device_buf, device_len, &other_securenet);
assert(error_code == ErrorCode.none);

/// try to login with wrong pin
string wrong_pincode = "4321";
securenet_t false_securenet;

error_code = tagion_decrypt_devicepin(&wrong_pincode[0], wrong_pincode.length, device_buf, device_len, &false_securenet);
assert(error_code == ErrorCode.exception, "should give exception with wrong pin");
assert(false_securenet.securenet is null, "should not have created a securenet");