ObjFW
OFSecureData.h
1 /*
2  * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #import "OFData.h"
17 
18 OF_ASSUME_NONNULL_BEGIN
19 
32 OF_SUBCLASSING_RESTRICTED
33 @interface OFSecureData: OFData
34 {
35  unsigned char *_Nullable _items;
36  size_t _count, _itemSize;
37  bool _freeWhenDone, _allowsSwappableMemory;
38  void *_page;
39 }
40 
44 @property (readonly, nonatomic) bool allowsSwappableMemory;
45 
52 @property (readonly, nonatomic) void *mutableItems OF_RETURNS_INNER_POINTER;
53 
66 + (void)preallocateUnswappableMemoryWithSize: (size_t)size;
67 
77 + (instancetype)dataWithCount: (size_t)count
78  allowsSwappableMemory: (bool)allowsSwappableMemory;
79 
90 + (instancetype)dataWithCount: (size_t)count
91  itemSize: (size_t)itemSize
92  allowsSwappableMemory: (bool)allowsSwappableMemory;
93 
94 + (instancetype)dataWithItems: (const void *)items
95  count: (size_t)count OF_UNAVAILABLE;
96 + (instancetype)dataWithItems: (const void *)items
97  count: (size_t)count
98  itemSize: (size_t)itemSize OF_UNAVAILABLE;
99 + (instancetype)dataWithItemsNoCopy: (void *)items
100  count: (size_t)count
101  freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE;
102 + (instancetype)dataWithItemsNoCopy: (void *)items
103  count: (size_t)count
104  itemSize: (size_t)itemSize
105  freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE;
106 #ifdef OF_HAVE_FILES
107 + (instancetype)dataWithContentsOfFile: (OFString *)path OF_UNAVAILABLE;
108 #endif
109 + (instancetype)dataWithContentsOfIRI: (OFIRI *)IRI OF_UNAVAILABLE;
110 + (instancetype)dataWithStringRepresentation: (OFString *)string OF_UNAVAILABLE;
111 + (instancetype)dataWithBase64EncodedString: (OFString *)string OF_UNAVAILABLE;
112 
122 - (instancetype)initWithCount: (size_t)count
123  allowsSwappableMemory: (bool)allowsSwappableMemory;
124 
135 - (instancetype)initWithCount: (size_t)count
136  itemSize: (size_t)itemSize
137  allowsSwappableMemory: (bool)allowsSwappableMemory
138  OF_DESIGNATED_INITIALIZER;
139 
140 - (instancetype)init OF_UNAVAILABLE;
141 - (instancetype)initWithItemSize: (size_t)itemSize OF_UNAVAILABLE;
142 - (instancetype)initWithItems: (const void *)items
143  count: (size_t)count OF_UNAVAILABLE;
144 - (instancetype)initWithItems: (const void *)items
145  count: (size_t)count
146  itemSize: (size_t)itemSize OF_UNAVAILABLE;
147 - (instancetype)initWithItemsNoCopy: (void *)items
148  count: (size_t)count
149  freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE;
150 - (instancetype)initWithItemsNoCopy: (void *)items
151  count: (size_t)count
152  itemSize: (size_t)itemSize
153  freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE;
154 #ifdef OF_HAVE_FILES
155 - (instancetype)initWithContentsOfFile: (OFString *)path OF_UNAVAILABLE;
156 #endif
157 - (instancetype)initWithContentsOfIRI: (OFIRI *)IRI OF_UNAVAILABLE;
158 - (instancetype)initWithStringRepresentation: (OFString *)string OF_UNAVAILABLE;
159 - (instancetype)initWithBase64EncodedString: (OFString *)string OF_UNAVAILABLE;
160 
170 - (void *)mutableItemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER;
171 
181 - (bool)isEqual: (nullable id)object;
182 
186 - (void)zero;
187 
188 - (OFString *)stringRepresentation OF_UNAVAILABLE;
189 - (OFString *)stringByBase64Encoding OF_UNAVAILABLE;
190 #ifdef OF_HAVE_FILES
191 - (void)writeToFile: (OFString *)path OF_UNAVAILABLE;
192 #endif
193 - (void)writeToIRI: (OFIRI *)IRI OF_UNAVAILABLE;
194 - (OFData *)messagePackRepresentation OF_UNAVAILABLE;
195 @end
196 
197 OF_ASSUME_NONNULL_END
A class for storing arbitrary data in an array.
Definition: OFData.h:42
A class for representing IRIs, URIs, URLs and URNs, for parsing them as well as accessing parts of th...
Definition: OFIRI.h:37
A class for storing arbitrary data in secure (non-swappable) memory, securely wiping it when it gets ...
Definition: OFSecureData.h:34
A class for handling strings.
Definition: OFString.h:135