Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
IHashAlgorithm.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* IHashAlgorithm.h (C) 2000-2023 */
9/* */
10/* Interface of a hashing algorithm. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_IHASHALGORITHM_H
13#define ARCANE_UTILS_IHASHALGORITHM_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19#include "arccore/base/Span.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
34class ARCANE_UTILS_EXPORT HashAlgorithmValue
35{
36 public:
37
38 static constexpr Int32 MAX_SIZE = 64;
39
40 public:
41
43 {
44 return { m_value.data(), m_size };
45 }
46 SmallSpan<const std::byte> bytes() const
47 {
48 return { m_value.data(), m_size };
49 }
50 SmallSpan<const Byte> asLegacyBytes() const
51 {
52 return { reinterpret_cast<const Byte*>(m_value.data()), m_size };
53 }
54 void setSize(Int32 size);
55
56 private:
57
58 std::array<std::byte, MAX_SIZE> m_value = {};
59 Int32 m_size = MAX_SIZE;
60};
61
62/*---------------------------------------------------------------------------*/
63/*---------------------------------------------------------------------------*/
64
84class ARCANE_UTILS_EXPORT IHashAlgorithmContext
85{
86 public:
87
88 virtual ~IHashAlgorithmContext() = default;
89
90 public:
91
93 virtual void reset() = 0;
94
96 virtual void updateHash(Span<const std::byte> input) = 0;
97
99 virtual void computeHashValue(HashAlgorithmValue& hash_value) = 0;
100};
101
102/*---------------------------------------------------------------------------*/
103/*---------------------------------------------------------------------------*/
104
108class ARCANE_UTILS_EXPORT IHashAlgorithm
109{
110 public:
111
112 virtual ~IHashAlgorithm() = default;
113
114 public:
115
116 //NOTE: for now (version 3.10) still pure virtual to remain
117 // compatible with existing code
119 virtual String name() const;
120
121 //NOTE: for now (version 3.10) still pure virtual to remain
122 // compatible with existing code. Throws FatalErrorException if not overridden
124 virtual Int32 hashSize() const;
125
132 virtual void computeHash64(Span<const Byte> input, ByteArray& output);
133
140 virtual void computeHash64(Span<const std::byte> input, ByteArray& output);
141
142 //NOTE: for now (version 3.10) still pure virtual to remain
143 // compatible with existing code
149 virtual void computeHash(Span<const std::byte> input, HashAlgorithmValue& value);
150
151 //NOTE: for now (version 3.11) still pure virtual to remain
152 // compatible with existing code
161
162 //NOTE: for now (version 3.11) still pure virtual to remain
163 // compatible with existing code
165 virtual bool hasCreateContext() const { return false; }
166
167 public:
168
175 ARCANE_DEPRECATED_REASON("Y2023: Use computeHash64(Span<const std::byte> input,ByteArray& output) instead")
176 virtual void computeHash(ByteConstArrayView input, ByteArray& output) = 0;
177};
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
181
182} // namespace Arcane
183
184/*---------------------------------------------------------------------------*/
185/*---------------------------------------------------------------------------*/
186
187#endif
Types and functions associated with the classes SpanImpl, SmallSpan and Span.
Declarations of types used in Arcane.
Hash algorithm return value.
Context for calculating a hash incrementally.
virtual void updateHash(Span< const std::byte > input)=0
Adds the array input to the calculated hash.
virtual void reset()=0
Resets the instance to calculate a new hash value.
virtual void computeHashValue(HashAlgorithmValue &hash_value)=0
Calculates the hash value and returns it in hash_value.
Interface of a hashing algorithm.
virtual bool hasCreateContext() const
Indicates if the implementation supports incremental hashing.
virtual String name() const
Name of the algorithm.
virtual void computeHash(Span< const std::byte > input, HashAlgorithmValue &value)
Calculates the hash value for the array input.
virtual void computeHash64(Span< const Byte > input, ByteArray &output)
Calculates the hash value for the array input.
virtual Int32 hashSize() const
Size (in bytes) of the hash key.
virtual Ref< IHashAlgorithmContext > createContext()
Creates a context to calculate the hash value incrementally.
Reference to an instance.
View of an array of elements of type T.
Definition Span.h:805
View of an array of elements of type T.
Definition Span.h:635
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Array< Byte > ByteArray
Dynamic one-dimensional array of characters.
Definition UtilsTypes.h:121
ConstArrayView< Byte > ByteConstArrayView
C equivalent of a 1D array of characters.
Definition UtilsTypes.h:476
unsigned char Byte
Type of a byte.
Definition BaseTypes.h:43
std::int32_t Int32
Signed integer type of 32 bits.