AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Public Types | Public Member Functions | List of all members
alexaClientSDK::cryptoInterfaces::DigestInterface Class Referenceabstract

Digest computation interface. More...

#include <DigestInterface.h>

Inheritance diagram for alexaClientSDK::cryptoInterfaces::DigestInterface:
Inheritance graph
[legend]

Public Types

typedef std::vector< unsigned char > DataBlock
 Data block type. This type represents a byte array. More...
 

Public Member Functions

virtual ~DigestInterface () noexcept=default
 Default destructor. More...
 
virtual bool process (const DataBlock &dataIn) noexcept=0
 Updates digest with a data block. More...
 
virtual bool process (DataBlock::const_iterator begin, DataBlock::const_iterator end) noexcept=0
 Updates digest with a data block range. More...
 
virtual bool processByte (unsigned char value) noexcept=0
 Updates digest with a byte value. More...
 
virtual bool processUInt8 (uint8_t value) noexcept=0
 Updates digest with uint8_t value. More...
 
virtual bool processUInt16 (uint16_t value) noexcept=0
 Updates digest with uint16_t integer value. More...
 
virtual bool processUInt32 (uint32_t value) noexcept=0
 Updates digest with uint32_t integer value. More...
 
virtual bool processUInt64 (uint64_t value) noexcept=0
 Updates digest with uint64_t integer value. More...
 
virtual bool processString (const std::string &value) noexcept=0
 Updates digest with string value. More...
 
virtual bool finalize (DataBlock &dataOut) noexcept=0
 Finishes digest computation and produces the result. More...
 
virtual bool reset () noexcept=0
 Resets the digest. More...
 

Detailed Description

Digest computation interface.

This interface wraps up logic for computing various digest types (SHA-2, RC5, etc.).

To compute the digest, the user shall call any of process methods to consume all input data, and when all data is consume, call finalize to get the result.

auto digest = cryptoFactory->createDigest(DigestType::SHA256);
codec->process(input);
codec->process(input);
codec->finalize(&digestData);

The instance of the class is reusable, and it also can be used if any of the methods returned an error code after call to reset().

Thread Safety

This interface is not thread safe and caller must ensure only one thread can make calls at any time.

Member Typedef Documentation

◆ DataBlock

Data block type. This type represents a byte array.

Constructor & Destructor Documentation

◆ ~DigestInterface()

virtual alexaClientSDK::cryptoInterfaces::DigestInterface::~DigestInterface ( )
virtualdefaultnoexcept

Default destructor.

Member Function Documentation

◆ finalize()

virtual bool alexaClientSDK::cryptoInterfaces::DigestInterface::finalize ( DataBlock dataOut)
pure virtualnoexcept

Finishes digest computation and produces the result.

This method finishes digest computation and produces the result. The object is reset if this call succeeds and can be reused for computing new digest.

Parameters
[out]dataOutComputed digest. The size of output depends on the selected digest algorithm. The method appends data to dataOut container.
Returns
True if operation has succeeded. This object state is reset and ready to start computing a new digest. If operation fails, the state of the object and contents of dataOut container are undefined. The user can call reset() to reuse the object in this case.

◆ process() [1/2]

virtual bool alexaClientSDK::cryptoInterfaces::DigestInterface::process ( const DataBlock dataIn)
pure virtualnoexcept

Updates digest with a data block.

Updates digest value with a data from a data block.

This call is logical equivalent to a following code:

for (b: dataIn) processUInt8(b);
Parameters
[in]dataInData for digest.
Returns
True if operation has succeeded. If operation fails, the state of object is undefined, and user must call reset() to reuse the object.

◆ process() [2/2]

virtual bool alexaClientSDK::cryptoInterfaces::DigestInterface::process ( DataBlock::const_iterator  begin,
DataBlock::const_iterator  end 
)
pure virtualnoexcept

Updates digest with a data block range.

Updates digest value with a data from a data block range.

This call is logical equivalent to a following code:

for (auto it = begin; it != end; ++it) processUInt8(*it);
Parameters
[in]beginBegin of data block. This parameter must be equal or less than end. If the parameter is greater than dataInEnd the implementation does nothing and returns false.
[in]endRange end. This parameter must be equal or greater than begin. If the parameter is smaller than begin the implementation does nothing and returns false.
Returns
True if operation has succeeded. If operation fails, the state of object is undefined, and user must call reset() to reuse the object.

◆ processByte()

virtual bool alexaClientSDK::cryptoInterfaces::DigestInterface::processByte ( unsigned char  value)
pure virtualnoexcept

Updates digest with a byte value.

Updates digest value with a single byte value.

Parameters
[in]valuebyte value.
Returns
True if operation has succeeded. If operation fails, the state of object is undefined, and user must call reset() to reuse the object.

◆ processString()

virtual bool alexaClientSDK::cryptoInterfaces::DigestInterface::processString ( const std::string &  value)
pure virtualnoexcept

Updates digest with string value.

Updates digest with bytes from a string object. The input is treated as a byte array without terminating null character.

This method is equivalent to the following:

for (auto ch: value) processByte(ch);
Parameters
[in]valueString value.
Returns
True if operation has succeeded. If operation fails, the state of object is undefined, and user must call reset() to reuse the object.

◆ processUInt16()

virtual bool alexaClientSDK::cryptoInterfaces::DigestInterface::processUInt16 ( uint16_t  value)
pure virtualnoexcept

Updates digest with uint16_t integer value.

Updates digest value with uint16_t data. This method uses big endian (network byte order) encoding for presenting input value as a byte array.

This method is equivalent to the following:

processUInt8(value >> 8) && processUInt8(value);
Parameters
[in]valueInteger value.
Returns
True if operation has succeeded. If operation fails, the state of object is undefined, and user must call reset() to reuse the object.

◆ processUInt32()

virtual bool alexaClientSDK::cryptoInterfaces::DigestInterface::processUInt32 ( uint32_t  value)
pure virtualnoexcept

Updates digest with uint32_t integer value.

Updates digest value with uint32_t data. This method uses big endian (network byte order) encoding for presenting input value as a byte array.

This method is equivalent to the following:

processUInt16(value >> 16) && processUInt16(value);
Parameters
[in]valueInteger value.
Returns
True if operation has succeeded. If operation fails, the state of object is undefined, and user must call reset() to reuse the object.

◆ processUInt64()

virtual bool alexaClientSDK::cryptoInterfaces::DigestInterface::processUInt64 ( uint64_t  value)
pure virtualnoexcept

Updates digest with uint64_t integer value.

Updates digest value with uint64_t data. This method uses big endian (network byte order) encoding for presenting input value as a byte array.

This method is equivalent to the following:

processUInt32((uint32_t)(value >> 32)) && processUInt32((uint32_t)value);
Parameters
[in]valueInteger value.
Returns
True if operation has succeeded. If operation fails, the state of object is undefined, and user must call reset() to reuse the object.

◆ processUInt8()

virtual bool alexaClientSDK::cryptoInterfaces::DigestInterface::processUInt8 ( uint8_t  value)
pure virtualnoexcept

Updates digest with uint8_t value.

Updates digest value with a 8-bit value.

Parameters
[in]valueInteger value.
Returns
True if operation has succeeded. If operation fails, the state of object is undefined, and user must call reset() to reuse the object.

◆ reset()

virtual bool alexaClientSDK::cryptoInterfaces::DigestInterface::reset ( )
pure virtualnoexcept

Resets the digest.

This method resets object state and prepares it for reuse.

Returns
True if operation has succeeded. If operation fails, the state of the object is undefined and the object must not used.

The documentation for this class was generated from the following file:

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0