Sailfish Crypto
API DocumentationGenerateRandomDataRequest Class
(Sailfish::Crypto::GenerateRandomDataRequest)Allows a client request that the system crypto service generate random data. More...
Header: | #include <Crypto/generaterandomdatarequest.h> |
Instantiated By: | GenerateRandomDataRequest |
Inherits: | Sailfish::Crypto::Request |
Properties
- cryptoPluginName : QString
- csprngEngineName : QString
- generatedData : const QByteArray
- numberBytes : quint64
- 4 properties inherited from Sailfish::Crypto::Request
Public Functions
GenerateRandomDataRequest(QObject *parent = Q_NULLPTR) | |
~GenerateRandomDataRequest() | |
QString | cryptoPluginName() const |
QString | csprngEngineName() const |
QByteArray | generatedData() const |
quint64 | numberBytes() const |
void | setCryptoPluginName(const QString &pluginName) |
void | setCsprngEngineName(const QString &engineName) |
void | setNumberBytes(quint64 nbrBytes) |
Reimplemented Public Functions
virtual QVariantMap | customParameters() const |
virtual Sailfish::Crypto::CryptoManager * | manager() const |
virtual Sailfish::Crypto::Result | result() const |
virtual void | setCustomParameters(const QVariantMap ¶ms) |
virtual void | setManager(Sailfish::Crypto::CryptoManager *manager) |
virtual void | startRequest() |
virtual Sailfish::Crypto::Request::Status | status() const |
virtual void | waitForFinished() |
- 8 public functions inherited from Sailfish::Crypto::Request
Signals
void | cryptoPluginNameChanged() |
void | csprngEngineNameChanged() |
void | generatedDataChanged() |
void | numberBytesChanged() |
- 4 signals inherited from Sailfish::Crypto::Request
Detailed Description
Allows a client request that the system crypto service generate random data.
The random data will be generated using the cryptographically-secure random number generator engine specified by the client. The engines which are supported by the plugin should be documented by that plugin. The default crypto plugin supports two engines: "default" and "/dev/urandom".
If you need a random number, you can use data from this method to create a random number. For example, to return a random number between 30 and 7777 you could do something like the following:
Sailfish::Crypto::GenerateRandomDataRequest rd; rd.setManager(cryptoManager); rd.setCryptoPluginName(Sailfish::Crypto::CryptoManager::DefaultCryptoStoragePluginName); rd.setCsprngEngineName(QStringLiteral("/dev/urandom")); rd.setNumberBytes(8); rd.startRequest(); rd.waitForFinished(); // in real code, you would not do this, but react to statusChanged() QByteArray randomBytes = rd.generatedData(); quint64 randomU64 = 0; memcpy(&randomU64, randomBytes.constData(), 8); double randomDouble = (randomU64 >> 11) * (1.0/9007199254740992.0); // 53 bits / 2**53 int randomInRange = qRound((7777 - 30) * randomDouble) + 30;
Property Documentation
cryptoPluginName : QString
Access functions:
QString | cryptoPluginName() const |
void | setCryptoPluginName(const QString &pluginName) |
Notifier signal:
void | cryptoPluginNameChanged() |
csprngEngineName : QString
Access functions:
QString | csprngEngineName() const |
void | setCsprngEngineName(const QString &engineName) |
Notifier signal:
void | csprngEngineNameChanged() |
generatedData : const QByteArray
Access functions:
QByteArray | generatedData() const |
Notifier signal:
void | generatedDataChanged() |
numberBytes : quint64
Access functions:
quint64 | numberBytes() const |
void | setNumberBytes(quint64 nbrBytes) |
Notifier signal:
void | numberBytesChanged() |
Member Function Documentation
GenerateRandomDataRequest::GenerateRandomDataRequest(QObject *parent = Q_NULLPTR)
Constructs a new GenerateRandomDataRequest object with the given parent.
GenerateRandomDataRequest::~GenerateRandomDataRequest()
Destroys the GenerateRandomDataRequest
QString GenerateRandomDataRequest::cryptoPluginName() const
Returns the name of the crypto plugin which the client wishes to perform the key generation operation
Note: Getter function for property cryptoPluginName.
See also setCryptoPluginName().
QString GenerateRandomDataRequest::csprngEngineName() const
Returns the name of the cryptographically secure random number generator engine offered by the crypto plugin which the client wishes to be used to generate the random data
Note: Getter function for property csprngEngineName.
See also setCsprngEngineName().
[virtual]
QVariantMap GenerateRandomDataRequest::customParameters() const
See also setCustomParameters().
QByteArray GenerateRandomDataRequest::generatedData() const
Returns the generated random data
Note: this value is only valid if the status of the request is Request::Finished.
Note: Getter function for property generatedData.
[virtual]
Sailfish::Crypto::CryptoManager *GenerateRandomDataRequest::manager() const
See also setManager().
quint64 GenerateRandomDataRequest::numberBytes() const
Returns the number of bytes of random data that the client wishes to be generated
Note: Getter function for property numberBytes.
See also setNumberBytes().
[virtual]
Sailfish::Crypto::Result GenerateRandomDataRequest::result() const
void GenerateRandomDataRequest::setCryptoPluginName(const QString &pluginName)
Sets the name of the crypto plugin which the client wishes to perform the key generation operation to pluginName
Note: Setter function for property cryptoPluginName.
See also cryptoPluginName().
void GenerateRandomDataRequest::setCsprngEngineName(const QString &engineName)
Sets the name of the cryptographically secure random number generator engine offered by the crypto plugin which the client wishes to be used to generate the random data to engineName
Usually, the default engine offered by the plugin is the correct CSPRNG engine to use (and in fact, most plugins will only offer that one engine), so clients should not have to set this parameter in the majority of cases.
Note: Setter function for property csprngEngineName.
See also csprngEngineName().
[virtual]
void GenerateRandomDataRequest::setCustomParameters(const QVariantMap ¶ms)
See also customParameters().
[virtual]
void GenerateRandomDataRequest::setManager(Sailfish::Crypto::CryptoManager *manager)
See also manager().
void GenerateRandomDataRequest::setNumberBytes(quint64 nbrBytes)
Sets the number of bytes of random data that the client wishes to be generated to nbrBytes
Note: Setter function for property numberBytes.
See also numberBytes().