ObjFW
OFCryptographicHash.h
1 /*
2  * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3.0 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * version 3.0 for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 3.0 along with this program. If not, see
17  * <https://www.gnu.org/licenses/>.
18  */
19 
20 #import "OFObject.h"
21 
22 OF_ASSUME_NONNULL_BEGIN
23 
35 #ifdef OF_HAVE_CLASS_PROPERTIES
36 @property (class, readonly, nonatomic) size_t digestSize;
37 @property (class, readonly, nonatomic) size_t blockSize;
38 #endif
39 
43 @property (readonly, nonatomic) size_t digestSize;
44 
48 @property (readonly, nonatomic) size_t blockSize;
49 
53 @property (readonly, nonatomic) bool allowsSwappableMemory;
54 
58 @property (readonly, nonatomic, getter=isCalculated) bool calculated;
59 
68 @property (readonly, nonatomic) const unsigned char *digest
69  OF_RETURNS_INNER_POINTER;
70 
76 + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory;
77 
83 + (size_t)digestSize;
84 
90 + (size_t)blockSize;
91 
97 - (instancetype)initWithAllowsSwappableMemory: (bool)allowsSwappableMemory;
98 
99 - (instancetype)init OF_UNAVAILABLE;
100 
108 - (void)updateWithBuffer: (const void *)buffer length: (size_t)length;
109 
115 - (void)calculate;
116 
124 - (void)reset;
125 @end
126 
127 OF_ASSUME_NONNULL_END
The root class for all other classes inside ObjFW.
Definition: OFObject.h:692
A protocol for the creation of copies.
Definition: OFObject.h:1350
A protocol for classes providing cryptographic hash functions.
Definition: OFCryptographicHash.h:34
void calculate()
Performs the final calculation of the cryptographic hash.
bool allowsSwappableMemory
Whether data may be stored in swappable memory.
Definition: OFCryptographicHash.h:53
bool calculated
A boolean whether the hash has already been calculated.
Definition: OFCryptographicHash.h:58
void reset()
Resets all state so that a new hash can be calculated.
size_t blockSize
The block size of the cryptographic hash, in bytes.
Definition: OFCryptographicHash.h:48
size_t digestSize
The digest size of the cryptographic hash, in bytes.
Definition: OFCryptographicHash.h:43
const unsigned char * digest
A buffer containing the cryptographic hash.
Definition: OFCryptographicHash.h:69