decoder-decode-data
- C
- C++
- CSharp
- Java
- JavaScript
- Swift
- Python
- Go
- PHP
/* There are different functions available to use depending on program needs.
* The versions with b64 in the function name involve base 64 conversion,
* suitable for protocols requiring a string representation.
* Otherwise the default will use raw bytes.
*/
/* Decode the message. */
MTE_SET_DEC_IO(d_args, e_args.encoded, e_args.bytes, decoded);
status = mte_dec_decode_b64(decoder, &d_args);
if (mte_base_status_is_error(status))
{
fprintf(stderr, "Decode error (%s): %s\n",
mte_base_status_name(status),
mte_base_status_description(status));
return status;
}
else if (status != mte_status_success)
{
fprintf(stderr, "Decode warning (%s): %s\n",
mte_base_status_name(status),
mte_base_status_description(status));
}
The timestamp callback.
static MTE_UINT64_T t_cb(void* context)
{
char line[80];
(void)context;
/* Get the timestamp. */
printf("Enter the timestamp (decimal digits only)> ");
fflush(stdout);
(void)!fgets(line, sizeof(line), stdin);
return strtoul(line, NULL, 10);
}
// There are different functions available to use depending on program needs.
// The versions with b64 in the function name involve base 64 conversion,
// suitable for protocols requiring a string representation.
// Otherwise the default will use raw bytes.
size_t decodedBytes = 0;
// Decode the message.
const void* decoded = decoder.decode(encoded, encodedBytes, decodedBytes, status);
if (MteBase::statusIsError(status))
{
std::cerr << "Decode error ("
<< MteBase::getStatusName(status)
<< "): "
<< MteBase::getStatusDescription(status)
<< std::endl;
return status;
}
else if (status != mte_status_success)
{
std::cerr << "Decode warning ("
<< MteBase::getStatusName(status)
<< "): "
<< MteBase::getStatusDescription(status)
<< std::endl;
}
The timestamp callback.
MTE_UINT64_T Cbs::timestampCallback()
{
// Display a prompt.
std::cout << "Enter the timestamp (decimal digits only)> " << std::flush;
// Get the timestamp and ignore the rest of the line.
MTE_UINT64_T u64;
std::cin >> u64;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return u64;
}
// initialize status
MteStatus decoderStatus;
// Below are 4 different examples of how to decode
// ONLY ONE needs to be used!!!
// Decode byte[] to a base64 string
string decodedBytesAsString = mteDecoder.DecodeStr(encodedBytes, out decoderStatus);
if (mteDecoder.StatusIsError(decoderStatus)) {
// Unable to decode, this checks for errors, handle failure appropriately
// Below is only an example
Console.Error.WriteLine("Decode error ({0}): {1}",
mteDecoder.GetStatusName(decoderStatus),
mteDecoder.GetStatusDescription(decoderStatus));
return (int)status;
// This catches Decoder warnings, the decode process was successful
// But depending on the type of security needed these may be ignored
// Please see Developer Guide for more details.
} else if (status != MteStatus.mte_status_success) {
Console.Error.WriteLine("Decode warning ({0}): {1}",
mteDecoder.GetStatusName(decoderStatus),
mteDecoder.GetStatusDescription(decoderStatus));
}
// Decode string to a base64 string
string decodedStringAsString = mteDecoder.DecodeStrB64(encodedBase64String, out decoderStatus);
if (mteDecoder.StatusIsError(decoderStatus)) {
// Unable to decode, this checks for errors, handle failure appropriately
// Below is only an example
Console.Error.WriteLine("Decode error ({0}): {1}",
mteDecoder.GetStatusName(decoderStatus),
mteDecoder.GetStatusDescription(decoderStatus));
return (int)status;
// This catches Decoder warnings, the decode process was successful
// But depending on the type of security needed these may be ignored
// Please see Developer Guide for more details.
} else if (status != MteStatus.mte_status_success) {
Console.Error.WriteLine("Decode warning ({0}): {1}",
mteDecoder.GetStatusName(decoderStatus),
mteDecoder.GetStatusDescription(decoderStatus));
// Decode byte[] to a byte[]
byte[] decodedBytes = mteDecoder.Decode(encodedBytes, out decoderStatus);
if (mteDecoder.StatusIsError(decoderStatus)) {
// Unable to decode, this checks for errors, handle failure appropriately
// Below is only an example
Console.Error.WriteLine("Decode error ({0}): {1}",
mteDecoder.GetStatusName(decoderStatus),
mteDecoder.GetStatusDescription(decoderStatus));
return (int)status;
// This catches Decoder warnings, the decode process was successful
// But depending on the type of security needed these may be ignored
// Please see Developer Guide for more details.
} else if (status != MteStatus.mte_status_success) {
Console.Error.WriteLine("Decode warning ({0}): {1}",
mteDecoder.GetStatusName(decoderStatus),
mteDecoder.GetStatusDescription(decoderStatus));
// Decode string to a byte[]
byte[] decodedStringAsBytes = mteDecoder.DecodeB64(encodedBase64String, out decoderStatus);
if (mteDecoder.StatusIsError(decoderStatus)) {
// Unable to decode, this checks for errors, handle failure appropriately
// Below is only an example
Console.Error.WriteLine("Decode error ({0}): {1}",
mteDecoder.GetStatusName(decoderStatus),
mteDecoder.GetStatusDescription(decoderStatus));
return (int)status;
// This catches Decoder warnings, the decode process was successful
// But depending on the type of security needed these may be ignored
// Please see Developer Guide for more details.
} else if (status != MteStatus.mte_status_success) {
Console.Error.WriteLine("Decode warning ({0}): {1}",
mteDecoder.GetStatusName(decoderStatus),
mteDecoder.GetStatusDescription(decoderStatus));
// Initiaze status
MteStatus decoderStatus;
// Below are 4 different examples of how to decode
// ONLY ONE needs to be used!!!
// Decode byte[] to a base64 string
MteBase.StrStatus decoded = mteDecoder.decodeStr(encodedBytes);
if (MteBase.statusIsError(decoded.status))
{
// Unable to decode, this checks for errors, handle failure appropriately
// Below is only an example
throw new Exception("Failed to decode. Status: "
+ MteBase.getStatusName(decoded.status)+ " / "
+ MteBase.getStatusDescription(decoded.status));
}
else if (decoded.status != MteStatus.mte_status_success)
{
// This catches Decoder warnings, the decode process was successful
// But depending on the type of security needed these may be ignored
// Please see Developer Guide for more details.
System.err.println("Decode warning ("
+ MteBase.getStatusName(decoded.status) + "): "
+ MteBase.getStatusDescription(decoded.status));
}
String decodedBytesAsString = decoded.str;
// Decode string to a base64 string
MteBase.StrStatus decoded = mteDecoder.decodeStrB64(encodedBase64String);
if (MteBase.statusIsError(decoded.status))
{
// Unable to decode, this checks for errors, handle failure appropriately
// Below is only an example
throw new Exception("Failed to decode. Status: "
+ MteBase.getStatusName(decoded.status)+ " / "
+ MteBase.getStatusDescription(decoded.status));
}
else if (decoded.status != MteStatus.mte_status_success)
{
// This catches Decoder warnings, the decode process was successful
// But depending on the type of security needed these may be ignored
// Please see Developer Guide for more details.
System.err.println("Decode warning ("
+ MteBase.getStatusName(decoded.status) + "): "
+ MteBase.getStatusDescription(decoded.status));
}
String decodedBytesAsString = decoded.str;
// Decode byte[] to a byte[]
MteBase.ArrStatus decoded = mteDecoder.decode(encodedBytes);
if (MteBase.statusIsError(decoded.status))
{
// Unable to decode, this checks for errors, handle failure appropriately
// Below is only an example
throw new Exception("Failed to decode. Status: "
+ MteBase.getStatusName(decoded.status)+ " / "
+ MteBase.getStatusDescription(decoded.status));
}
else if (decoded.status != MteStatus.mte_status_success)
{
// This catches Decoder warnings, the decode process was successful
// But depending on the type of security needed these may be ignored
// Please see Developer Guide for more details.
System.err.println("Decode warning ("
+ MteBase.getStatusName(decoded.status) + "): "
+ MteBase.getStatusDescription(decoded.status));
}
byte[] decodedBytesAsBytes = decoded.arr;
// Decode string to a byte[]
MteBase.ArrStatus decoded = mteDecoder.(encodedBase64String);
if (MteBase.statusIsError(decoded.status))
{
// Unable to decode, this checks for errors, handle failure appropriately
// Below is only an example
throw new Exception("Failed to decode. Status: "
+ MteBase.getStatusName(decoded.status)+ " / "
+ MteBase.getStatusDescription(decoded.status));
}
else if (decoded.status != MteStatus.mte_status_success)
{
// This catches Decoder warnings, the decode process was successful
// But depending on the type of security needed these may be ignored
// Please see Developer Guide for more details.
System.err.println("Decode warning ("
+ MteBase.getStatusName(decoded.status) + "): "
+ MteBase.getStatusDescription(decoded.status));
}
byte[] decodedStringAsBytes = decoded.arr;
// decode string and return as B64 string
const decoderResult = mteDecoder.decodeStrB64(str);
if (mteDecoder.statusIsError(decoderResult.status)) {
// Unable to decode, this checks for errors, handle failure appropriately
// Below is only an example
const status = mteDecoder.getStatusName(decoderResult.status);
const message = mteDecoder.getStatusDescription(decoderResult.status);
throw new Error(`Error when MTE decoding data.\n${status}: ${message}`);
return;
} else if (decoderResult.status != MteStatus.mte_status_success) {
// This catches Decoder warnings, the decode process was successful
// But depending on the type of security needed these may be ignored
// Please see Developer Guide for more details.
alert(
"Decode warning (" +
mteDecoder.getStatusName(decoderResult.status) +
"): " +
mteDecoder.getStatusDescription(decoderResult.status),
);
}
console.log(`Decode result is: ${decoderResult.str}`);
// decode string and return as Uint8Array
const decoderResult = mteDecoder.decoderStr(str);
if (mteDecoder.statusIsError(decoderResult.status)) {
// Unable to decode, this checks for errors, handle failure appropriately
// Below is only an example
const status = mteDecoder.getStatusName(decoderResult.status);
const message = mteDecoder.getStatusDescription(decoderResult.status);
throw new Error(`Error when MTE decoding data.\n${status}: ${message}`);
return;
} else if (decoderResult.status != MteStatus.mte_status_success) {
// This catches Decoder warnings, the decode process was successful
// But depending on the type of security needed these may be ignored
// Please see Developer Guide for more details.
alert(
"Decode warning (" +
mteDecoder.getStatusName(decoderResult.status) +
"): " +
mteDecoder.getStatusDescription(decoderResult.status),
);
}
console.log(`Decode result is: ${decoderResult.arr}`);
// decode Uint8Array and return as b64 string
const decoderResult = mteDecoder.decodeB64(arr);
if (mteDecoder.statusIsError(decoderResult.status)) {
// Unable to decode, this checks for errors, handle failure appropriately
// Below is only an example
const status = mteDecoder.getStatusName(decoderResult.status);
const message = mteDecoder.getStatusDescription(decoderResult.status);
throw new Error(`Error when MTE decoding data.\n${status}: ${message}`);
return;
} else if (decoderResult.status != MteStatus.mte_status_success) {
// This catches Decoder warnings, the decode process was successful
// But depending on the type of security needed these may be ignored
// Please see Developer Guide for more details.
alert(
"Decode warning (" +
mteDecoder.getStatusName(decoderResult.status) +
"): " +
mteDecoder.getStatusDescription(decoderResult.status),
);
}
console.log(`Decode result is: ${decoderResult.str}`);
// decode Uint8Array and return as Uint8Array
const decoderResult = mteDecoder.decode(arr);
if (mteDecoder.statusIsError(decoderResult.status)) {
// Unable to decode, this checks for errors, handle failure appropriately
// Below is only an example
const status = mteDecoder.getStatusName(decoderResult.status);
const message = mteDecoder.getStatusDescription(decoderResult.status);
throw new Error(`Error when MTE decoding data.\n${status}: ${message}`);
return;
} else if (decoderResult.status != MteStatus.mte_status_success) {
// This catches Decoder warnings, the decode process was successful
// But depending on the type of security needed these may be ignored
// Please see Developer Guide for more details.
alert(
"Decode warning (" +
mteDecoder.getStatusName(decoderResult.status) +
"): " +
mteDecoder.getStatusDescription(decoderResult.status),
);
}
console.log(`Decode result is: ${decoderResult.arr}`);
// There are different functions available to use depending on program needs.
// The versions with b64 in the function name involve base 64 conversion,
// suitable for protocols requiring a string representation.
// Otherwise the default will use raw bytes.
// Decode the message.
let decoded = decoder.decode(Array(encodedRes.encoded))
status = decoded.status
if (MteBase.statusIsError(status)) {
print("Decode error (\(MteBase.getStatusName(status))): " +
MteBase.getStatusDescription(status))
return Int32(status.rawValue)
} else if (status != mte_status_success) {
print("Decode warning (\(MteBase.getStatusName(status))): " +
MteBase.getStatusDescription(status))
}
The timestamp callback.
func timestampCallback() -> UInt64 {
// Display a prompt.
print("Enter the timestamp (decimal digits only)> ", terminator: "")
// Get the timestamp and ignore the rest of the line.
return UInt64(readLine()!)!
}
# Below are 4 different examples of how to decode.
# ONLY ONE needs to be used.
# Decode byte[] to a base64 string.
(decoded_bytes_as_string, decoder_status) = mte_decoder.decode_str(encoded_bytes)
if MteBase.status_is_error(decoder_status):
# Handle decode failure appropriately.
# Below is only an example.
raise Exception("Failed to decode. Status: {0} / {1}\n".format(MteBase.get_status_name(decoder_status),
MteBase.get_status_description(decoder_status)))
elif decoder_status != MteStatus.mte_status_success:
# This catches Decoder warnings, the decode process was successful
# But depending on the type of security needed these may be ignored
# Please see Developer Guide for more details.
print("Decode warning ({0}): {1}".format(
MteBase.get_status_name(status),
MteBase.get_status_description(status)),
file=sys.stderr)
# Decode string to a base64 string.
(decoded_string_as_string, decoder_status) = mte_decoder.decode_str_b64(encoded_base64_string)
if MteBase.status_is_error(decoder_status):
# Handle decode failure appropriately.
# Below is only an example.
raise Exception("Failed to decode. Status: {0} / {1}\n".format(MteBase.get_status_name(decoder_status),
MteBase.get_status_description(decoder_status)))
elif decoder_status != MteStatus.mte_status_success:
# This catches Decoder warnings, the decode process was successful
# But depending on the type of security needed these may be ignored
# Please see Developer Guide for more details.
print("Decode warning ({0}): {1}".format(
MteBase.get_status_name(status),
MteBase.get_status_description(status)),
file=sys.stderr)
# Decode byte[] to a byte[].
(decoded_bytes, decoder_status) = mte_decoder.decode(encoded_bytes)
if MteBase.status_is_error(decoder_status):
# Handle decode failure appropriately.
# Below is only an example.
raise Exception("Failed to decode. Status: {0} / {1}\n".format(MteBase.get_status_name(decoder_status),
MteBase.get_status_description(decoder_status)))
elif decoder_status != MteStatus.mte_status_success:
# This catches Decoder warnings, the decode process was successful
# But depending on the type of security needed these may be ignored
# Please see Developer Guide for more details.
print("Decode warning ({0}): {1}".format(
MteBase.get_status_name(status),
MteBase.get_status_description(status)),
file=sys.stderr)
# Decode string to a byte[].
(decoded_string_as_bytes, decoder_status) = mte_decoder.decode_b64(encoded_base64_string)
if MteBase.status_is_error(decoder_status):
# Handle decode failure appropriately.
# Below is only an example.
raise Exception("Failed to decode. Status: {0} / {1}\n".format(MteBase.get_status_name(decoder_status),
MteBase.get_status_description(decoder_status)))
elif decoder_status != MteStatus.mte_status_success:
# This catches Decoder warnings, the decode process was successful
# But depending on the type of security needed these may be ignored
# Please see Developer Guide for more details.
print("Decode warning ({0}): {1}".format(
MteBase.get_status_name(status),
MteBase.get_status_description(status)),
file=sys.stderr)
// initialize status
var decoderStatus mte.Status
// Below are 4 different examples of how to decode
// ONLY ONE needs to be used!!!
// decode byte[] to base64 string
decodedBytesAsString, decodedStatus := mteDecoder.DecodeStr(encodedBytes)
if mte.StatusIsError(decodedStatus) {
// Handle error correctly
// Below is an example
fmt.Fprintf(os.Stderr, "Decode error (%v): %v\n",
mte.GetStatusName(decodedStatus), mte.GetStatusDescription(decodedStatus))
return int(status)
} else if decodedStatus != mte.Status_mte_status_success {
// Handle warning correctly
// Below is an example
fmt.Fprintf(os.Stderr, "Decode warning (%v): %v\n",
mte.GetStatusName(decodedStatus), mte.GetStatusDescription(decodedStatus))
}
// decode string to base64 string
decodedStringAsString, decodedStatus := mteDecoder.DecodeStrB64(encodedString)
if mte.StatusIsError(decodedStatus) {
// Handle error correctly
// Below is an example
fmt.Fprintf(os.Stderr, "Decode error (%v): %v\n",
mte.GetStatusName(decodedStatus), mte.GetStatusDescription(decodedStatus))
return int(status)
} else if decodedStatus != mte.Status_mte_status_success {
// Handle warning correctly
// Below is an example
fmt.Fprintf(os.Stderr, "Decode warning (%v): %v\n",
mte.GetStatusName(decodedStatus), mte.GetStatusDescription(decodedStatus))
}
// decode bytes to byte
decodedBytes, decodedStatus := mteDecoder.Decode(encodedBytes)
if mte.StatusIsError(decodedStatus) {
// Handle error correctly
// Below is an example
fmt.Fprintf(os.Stderr, "Decode error (%v): %v\n",
mte.GetStatusName(decodedStatus), mte.GetStatusDescription(decodedStatus))
return int(status)
} else if decodedStatus != mte.Status_mte_status_success {
// Handle warning correctly
// Below is an example
fmt.Fprintf(os.Stderr, "Decode warning (%v): %v\n",
mte.GetStatusName(decodedStatus), mte.GetStatusDescription(decodedStatus))
}
// decode string to bytes
decodedBytes, decodedStatus := mteDecoder.DecodeB64(encodedString)
if mte.StatusIsError(decodedStatus) {
// Handle error correctly
// Below is an example
fmt.Fprintf(os.Stderr, "Decode error (%v): %v\n",
mte.GetStatusName(decodedStatus), mte.GetStatusDescription(decodedStatus))
return int(status)
} else if decodedStatus != mte.Status_mte_status_success {
// Handle warning correctly
// Below is an example
fmt.Fprintf(os.Stderr, "Decode warning (%v): %v\n",
mte.GetStatusName(decodedStatus), mte.GetStatusDescription(decodedStatus))
}
<?php
// Decode String to String
$decoded = $mteDecoder->decode($encoded["str"]);
// Check the status
if (constant($decoded["status"])!=mte_status_success){
// Handle an error here -- below is a sample
throw new Exception("Decoder decode error: "
.$mteDecoder->getStatusName(constant($decoded["status"])).":"
.$mteDecoder->getStatusDescription(constant($decoded["status"])));
}
?>
<?php
// Decode Base64 string to string
$decoded = $mteDecoder->decodeB64($encoded["str"]);
// Check the status
if (constant($decoded["status"])!=mte_status_success){
// Handle an error here -- below is a sample
throw new Exception("Decoder decode error: "
.$mteDecoder->getStatusName(constant($decoded["status"])).":"
.$mteDecoder->getStatusDescription(constant($decoded["status"])));
}
?>