$darkmode
Elektra 0.11.0
Functions
hash.c File Reference

Provides functions to hash Elektra data structures. More...

#include <kdb.h>
#include <kdbease.h>
#include <kdberrors.h>
#include <kdbtypes.h>
#include <stdio.h>
#include <string.h>
#include "sha-256.h"
Include dependency graph for hash.c:

Functions

kdb_boolean_t calculateSpecificationToken (char hash_string[65], KeySet *ks, Key *parentKey)
 Calculate a specification token for the KeySet of an application. More...
 

Detailed Description

Provides functions to hash Elektra data structures.

Function Documentation

◆ calculateSpecificationToken()

kdb_boolean_t calculateSpecificationToken ( char  hash_string[65],
KeySet *  ks,
Key *  parentKey 
)

Calculate a specification token for the KeySet of an application.

The KeySet of an application is identified as all keys below the applications root key.

Precondition
The parentKey must have the correct namespace. E.g. If only keys from the spec:/ should be considered for the token calculation, pass a key with KEY_NS_SPEC.
Note
Array parent key's (e.g., /format/#) are ignored for the token. See inline documentation below for rationale.
Parameters
hash_stringA string. After successful execution this will contain the hash as hex-string.
ksThe KeySet for the application.
parentKeyThe Key below which all the relevant keys are. Keys that are not below parentKey are ignored. The key's namespace is important (see preconditions)
Return values
falseIf an error occurred.
trueIf the computation was successful.

Loop through all keys relevant for token calculation.

Ignore array parents for token calculation. Rationale: There is a bug in the spec plugin that is triggered on changing the size of an array. It leads to array parents vanishing from the spec namespace and thus a different token. See https://github.com/ElektraInitiative/libelektra/issues/4061

Include NULL teminator in this and all following key/value strings, to avoid the following bug: https://github.com/ElektraInitiative/libelektra/issues/4110