Drake
Drake C++ Documentation
Sha256 Class Referencefinal

Detailed Description

Represents a SHA-256 cryptographic checksum.

See also https://en.wikipedia.org/wiki/SHA-2.

This class is not bound in pydrake, because Python programmers should prefer using https://docs.python.org/3/library/hashlib.html instead.

#include <drake/common/sha256.h>

Public Member Functions

 Sha256 ()
 Constructs an all-zero checksum. More...
 
std::string to_string () const
 Returns the 64-character ASCII hex representation of this checksum. More...
 
bool operator== (const Sha256 &other) const
 
bool operator!= (const Sha256 &other) const
 
bool operator< (const Sha256 &other) const
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 Sha256 (const Sha256 &)=default
 
Sha256operator= (const Sha256 &)=default
 
 Sha256 (Sha256 &&)=default
 
Sha256operator= (Sha256 &&)=default
 

Static Public Member Functions

static Sha256 Checksum (std::string_view data)
 Computes the checksum of the given data buffer. More...
 
static Sha256 Checksum (std::istream *stream)
 Computes the checksum of the given stream. More...
 
static std::optional< Sha256Parse (std::string_view sha256)
 Parses the 64-character ASCII hex representation of a SHA-256 checksum. More...
 

Friends

class std::hash< Sha256 >
 

Constructor & Destructor Documentation

◆ Sha256() [1/3]

Sha256 ( const Sha256 )
default

◆ Sha256() [2/3]

Sha256 ( Sha256 &&  )
default

◆ Sha256() [3/3]

Sha256 ( )

Constructs an all-zero checksum.

Note that this is NOT the same as the checksum of empty (zero-sized) data.

Member Function Documentation

◆ Checksum() [1/2]

static Sha256 Checksum ( std::string_view  data)
static

Computes the checksum of the given data buffer.

◆ Checksum() [2/2]

static Sha256 Checksum ( std::istream *  stream)
static

Computes the checksum of the given stream.

Does not check for istream errors; that is the responsibility of the caller.

Precondition
stream != nullptr.

◆ operator!=()

bool operator!= ( const Sha256 other) const

◆ operator<()

bool operator< ( const Sha256 other) const

◆ operator=() [1/2]

Sha256& operator= ( Sha256 &&  )
default

◆ operator=() [2/2]

Sha256& operator= ( const Sha256 )
default

◆ operator==()

bool operator== ( const Sha256 other) const

◆ Parse()

static std::optional<Sha256> Parse ( std::string_view  sha256)
static

Parses the 64-character ASCII hex representation of a SHA-256 checksum.

Returns std::nullopt if the argument is an invalid checksum.

◆ to_string()

std::string to_string ( ) const

Returns the 64-character ASCII hex representation of this checksum.

Friends And Related Function Documentation

◆ std::hash< Sha256 >

friend class std::hash< Sha256 >
friend

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