Code View

plugin / plugin-2.2.0.0 / src / sign / TrustLevel.hh
// SPDX-License-Identifier: MIT
// sign/TrustLevel.hh
#pragma once
//
// fedem::sign::TrustLevel — trust classification for a signed DSO.
//
// Used by Verifier::verify() and by DSOLoader::loadSigned() /
// DSOLoader::loadVerified().  The host application decides what
// to do with each level; this library enforces nothing by default.

#include <string>

namespace fedem {
namespace sign {

// ─────────────────────────────────────────────────────────────────────────────
enum class TrustLevel
{
    TRUSTED,    ///< Valid signature; signer key found in trusted-keys directory
    UNKNOWN,    ///< Valid signature; signer key NOT in trusted-keys directory
    UNSIGNED,   ///< No manifest or signature sections present in the DSO
    REJECTED,   ///< Signature present but cryptographically invalid,
                ///< or SHA-256 of the DSO does not match the manifest
};

// ─────────────────────────────────────────────────────────────────────────────
inline const char* trustLevelName( TrustLevel t ) noexcept
{
    switch( t )
    {
        case TrustLevel::TRUSTED:  return "TRUSTED";
        case TrustLevel::UNKNOWN:  return "UNKNOWN";
        case TrustLevel::UNSIGNED: return "UNSIGNED";
        case TrustLevel::REJECTED: return "REJECTED";
    }
    return "UNKNOWN";
}

// Convenience: returns true for the levels that indicate a signature was
// present and cryptographically valid (regardless of key trust).
inline bool isSignatureValid( TrustLevel t ) noexcept
{
    return t == TrustLevel::TRUSTED || t == TrustLevel::UNKNOWN;
}

} // namespace sign
} // namespace fedem