About
The maxon::StreamConversionInterface provides a generic interface for any kind of data conversion. This includes string encoding, compression, encryption, hashing etc.
StreamConversionInterface
Conversion
maxon::StreamConversionInterface is used to convert the given source data. The result of this conversion is typically stored in a given array.
- Note
- A maxon::StreamConversionInterface object can be used only once.
const maxon::StreamConversionRef base64encoder = maxon::StreamConversions::Base64Encoder().Create()
iferr_return;
base64encoder.Convert(
source, destination, targetSizeEstimation,
true, lastPart)
iferr_return;
Definition: basearray.h:412
Definition: string.h:1235
const Py_UNICODE * source
Definition: unicodeobject.h:54
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:188
bool Bool
boolean type, possible values are only false/true, 8 bit
Definition: apibase.h:181
float Float32
32 bit floating point value (float)
Definition: apibase.h:182
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
#define iferr_return
Definition: resultbase.h:1519
const maxon::StreamConversionRef base64encoder = maxon::StreamConversions::Base64Encoder().Create()
iferr_return;
Streams
A given conversion instance can be converted to an input stream. See InputStream Manual.
maxon::InputStreamRef inputStream = maxon::InputStreamInterface::FromBlock().Create(memblock,
false)
iferr_return;
const maxon::StreamConversionRef base64encoder = maxon::StreamConversions::Base64Encoder().Create()
iferr_return;
inputStream = base64encoder.ConvertToStream(inputStream)
iferr_return;
const char ** buffer
Definition: abstract.h:327
Py_ssize_t count
Definition: abstract.h:640
PyObject * string
Definition: asdl.h:6
Block< const Char > CharToBlock(const Char *str)
Definition: block.h:1016
Properties
Various properties of the given conversion type can be accessed with:
{
const maxon::Id decoderID = encoder.GetCounterpart();
if (decoder.GetSourceType() != charDataType)
if (decoder.GetDestinationType() != charDataType)
}
MAXON_ATTRIBUTE_FORCE_INLINE Int GetCount() const
Definition: basearray.h:573
Definition: datatypebase.h:772
Definition: apibaseid.h:253
Definition: resultbase.h:766
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
const Class< R > & Get(const Id &cls)
Definition: objectbase.h:2073
#define iferr_scope
Definition: resultbase.h:1384
Conversions
Existing conversions are registered at the registry maxon::StreamConversions or presented as published objects. Some conversions can be configured by defining some settings in a maxon::DataDictionary that is used with the Create()
function (maxon::StreamConversionFactory).
Hex
Arbitrary data can be converted to a hexadecimal representation:
- maxon::StreamConversions::HexEncoder: Hexadecimal encoder.
- maxon::StreamConversions::HexDecoder: Hexadecimal decoder.
See also maxon::GetHexadecimalValue().
const maxon::StreamConversionRef encoder = maxon::StreamConversions::HexEncoder().Create()
iferr_return;
char Char
signed 8 bit character
Definition: apibase.h:184
UTF
Text can be converted to different Unicode encodings. See maxon::UTFTEXT_OPTIONS.
- maxon::StreamConversions::UtfTextEncoder: Unicode encoder.
- maxon::StreamConversions::UtfTextDecoder: Unicode decoder.
Additional string conversions are registered at maxon::StringEncodings and maxon::StringDecodings, see stringencoding.h
. For string conversions there are also maxon::StringEncodingInterface and maxon::StringDecodingInterface.
Base64
Arbitrary data can be converted to a Base64 representation. See maxon::BASE64_OPTIONS.
- maxon::StreamConversions::Base64Encoder: Base64 encoder.
- maxon::StreamConversions::Base64Decoder: Base64 decoder.
- maxon::StreamConversions::Base64UrlEncoder: Base64 URL encoder.
- maxon::StreamConversions::Base64UrlDecoder: Base64 URL decoder.
{
const maxon::StreamConversionRef encoder = maxon::StreamConversions::Base64Encoder().Create()
iferr_return;
}
{
const maxon::StreamConversionRef decoder = maxon::StreamConversions::Base64Decoder().Create()
iferr_return;
}
const char * message
Definition: pyerrors.h:189
#define MAXON_SCOPE
Definition: apibase.h:2841
Cryptography
Arbitrary data can be encrypted using these algorithms:
- maxon::StreamConversions::AesEncoder: AES encryption.
- maxon::StreamConversions::AesDecoder: AES decryption.
- maxon::StreamConversions::BlowfishEncoder: Blowfish encryption.
- maxon::StreamConversions::BlowfishDecoder: Blowfish decryption.
- maxon::StreamConversions::BlowfishLegacyEncoder: Legacy Blowfish encryption.
- maxon::StreamConversions::BlowfishLegacyDecoder: Legacy Blowfish decryption.
- maxon::StreamConversions::BlowfishLegacyEnDecoder: Legacy Blowfish en/decryption. See maxon::BLOWFISHLEGACYENDECODER_OPTIONS.
The cryptographic key is set as maxon::CryptographyOptions::CRYPTOKEY using maxon::CryptoKeyInterface. To pad a data block with arbitrary data use maxon::SecureRandom.
Encryption algorithms can also be used with the specialized maxon::CryptographyStreamConversionInterface.
const maxon::Id encoderID = maxon::StreamConversions::AesEncoder.GetId();
maxon::DataDictionary cryptoSettings;
cryptoSettings.Set(maxon::CryptographyOptions::CRYPTOKEY, cryptoKey)
iferr_return;
{
const maxon::StreamConversionRef aesEncoder = maxon::StreamConversions::AesEncoder().Create(cryptoSettings)
iferr_return;
const maxon::Int aesBlockSize = aesEncoder.GetBlockSize() * (aesEncoder.GetSourceType().GetSize() * 8);
const maxon::Int targetSize = ((initialSize + (aesBlockSize / 8) - 1) / (blockSize / 8)) * (aesBlockSize / 8);
if (diff > 0)
{
const auto randomDataBlock = maxon::ToBlock<maxon::UChar>(randomDataStart, randomDataSize);
}
if (!aesEncoder.SupportInplaceConversion())
}
{
const maxon::StreamConversionRef aesDecoder = maxon::StreamConversions::AesDecoder().Create(cryptoSettings)
iferr_return;
if (!aesDecoder.SupportInplaceConversion())
}
PyObject * key
Definition: abstract.h:289
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append(ARG &&x)
Definition: basearray.h:677
MAXON_ATTRIBUTE_FORCE_INLINE const T * GetFirst() const
Definition: basearray.h:1326
ResultMem Resize(Int newCnt, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::DEFAULT)
Definition: basearray.h:1369
Reference counted class of CryptoKeyInterface.
Definition: cryptography_key.h:122
static MAXON_METHOD SecureRandomProvider GetDefaultProvider()
static MAXON_METHOD Bool GetRandomNumber(SecureRandomProvider provider, const Block< Byte > &buffer)
unsigned char UChar
unsigned 8 bit character
Definition: apibase.h:185
Hashes
Hash values for arbitrary data are calculated with these algorithms:
- maxon::StreamConversions::HashMD5: MD5 hash algorithm.
- maxon::StreamConversions::HashSHA1: SHA1 hash algorithm.
- maxon::StreamConversions::HashSHA256: SHA256 hash algorithm.
- maxon::StreamConversions::HashSHA512: SHA512 hash algorithm.
- maxon::StreamConversions::HashCrc32c: Crc32c hash algorithm. For convenience see also maxon::Crc32C.
- maxon::StreamConversions::HashCrc32zip: Crc32zip hash algorithm.
- maxon::StreamConversions::HashHmac: Hash-based message authentication code. See maxon::HASH_HMAC.
const maxon::StreamConversionRef md5 = maxon::StreamConversions::HashMD5().Create()
iferr_return;
const maxon::StreamConversionRef sha256 = maxon::StreamConversions::HashSHA256().Create()
iferr_return;
PyObject Py_hash_t hash
Definition: dictobject.h:35
Result< String > GetHashString(const BaseArray< UChar > &hashValue)
Result< String > GetPasswordHash(const String &password, const StreamConversionFactory &hashClass, const DataDictionary &settings=DataDictionary())
PyObject * text
Definition: pycore_traceback.h:70
For easily handling passwords and hash strings see
auto factory = maxon::StreamConversions::HashSHA256();
Py_UCS4 * res
Definition: unicodeobject.h:1113
Result< Tuple< String, String > > HashPasswordWithSalt(const String &password, const StreamConversionFactory &hashClass=StreamConversions::HashSHA256())
Compression
Arbitrary data can be compressed using these algorithms. See datacompression.h:
- Note
- For creating ZIP archives see Archives Manual.
maxon::DataDictionary settings;
// decompress
maxon::BaseArray<maxon::Char> decompressed;
const maxon::StreamConversionRef zipDecoder = maxon::StreamConversions::ZipDecoder().Create(settings) iferr_return;
zipDecoder.ConvertAll(compressed, decompressed) iferr_return;
const maxon::String message(decompressed);
DiagnosticOutput("Uncompressed Message: @", message);
#define Set(a0, a1, a2, a3, a4, a5)
Definition: Python-ast.h:586
maxon::Char Char
Definition: ge_sys_math.h:56
maxon::Float Float
Definition: ge_sys_math.h:66
maxon::Int Int
Definition: ge_sys_math.h:64
static auto Create(ARGS &&... args)
Definition: apibase.h:2773
Int GetCount(const ITERABLE &iterable)
Definition: collection.h:37
The maxon namespace contains all declarations of the MAXON API.
Definition: autoweight.h:14
ZIP
Definition: network_smtpmail.h:21
Further Reading