ObjFW
OFSecureData.h
1 /*
2  * Copyright (c) 2008-2021 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  struct page *_page;
36  bool _allowsSwappableMemory;
37 }
38 
42 @property (readonly, nonatomic) bool allowsSwappableMemory;
43 
50 @property (readonly, nonatomic) void *mutableItems OF_RETURNS_INNER_POINTER;
51 
64 + (void)preallocateUnswappableMemoryWithSize: (size_t)size;
65 
75 + (instancetype)dataWithCount: (size_t)count
76  allowsSwappableMemory: (bool)allowsSwappableMemory;
77 
88 + (instancetype)dataWithCount: (size_t)count
89  itemSize: (size_t)itemSize
90  allowsSwappableMemory: (bool)allowsSwappableMemory;
91 
92 + (instancetype)dataWithItems: (const void *)items
93  count: (size_t)count OF_UNAVAILABLE;
94 + (instancetype)dataWithItems: (const void *)items
95  count: (size_t)count
96  itemSize: (size_t)itemSize OF_UNAVAILABLE;
97 + (instancetype)dataWithItemsNoCopy: (void *)items
98  count: (size_t)count
99  freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE;
100 + (instancetype)dataWithItemsNoCopy: (void *)items
101  count: (size_t)count
102  itemSize: (size_t)itemSize
103  freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE;
104 #ifdef OF_HAVE_FILES
105 + (instancetype)dataWithContentsOfFile: (OFString *)path OF_UNAVAILABLE;
106 #endif
107 + (instancetype)dataWithContentsOfURL: (OFURL *)URL OF_UNAVAILABLE;
108 + (instancetype)dataWithStringRepresentation: (OFString *)string OF_UNAVAILABLE;
109 + (instancetype)dataWithBase64EncodedString: (OFString *)string OF_UNAVAILABLE;
110 
120 - (instancetype)initWithCount: (size_t)count
121  allowsSwappableMemory: (bool)allowsSwappableMemory;
122 
133 - (instancetype)initWithCount: (size_t)count
134  itemSize: (size_t)itemSize
135  allowsSwappableMemory: (bool)allowsSwappableMemory
136  OF_DESIGNATED_INITIALIZER;
137 
138 - (instancetype)initWithItems: (const void *)items
139  count: (size_t)count OF_UNAVAILABLE;
140 - (instancetype)initWithItems: (const void *)items
141  count: (size_t)count
142  itemSize: (size_t)itemSize OF_UNAVAILABLE;
143 - (instancetype)initWithItemsNoCopy: (void *)items
144  count: (size_t)count
145  freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE;
146 - (instancetype)initWithItemsNoCopy: (void *)items
147  count: (size_t)count
148  itemSize: (size_t)itemSize
149  freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE;
150 #ifdef OF_HAVE_FILES
151 - (instancetype)initWithContentsOfFile: (OFString *)path OF_UNAVAILABLE;
152 #endif
153 - (instancetype)initWithContentsOfURL: (OFURL *)URL OF_UNAVAILABLE;
154 - (instancetype)initWithStringRepresentation: (OFString *)string OF_UNAVAILABLE;
155 - (instancetype)initWithBase64EncodedString: (OFString *)string OF_UNAVAILABLE;
156 - (instancetype)initWithSerialization: (OFXMLElement *)element OF_UNAVAILABLE;
157 
167 - (void *)mutableItemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER;
168 
178 - (bool)isEqual: (nullable id)object;
179 
183 - (void)zero;
184 
185 - (OFString *)stringRepresentation OF_UNAVAILABLE;
186 - (OFString *)stringByBase64Encoding OF_UNAVAILABLE;
187 #ifdef OF_HAVE_FILES
188 - (void)writeToFile: (OFString *)path OF_UNAVAILABLE;
189 #endif
190 - (void)writeToURL: (OFURL *)URL OF_UNAVAILABLE;
191 - (OFXMLElement *)XMLElementBySerializing OF_UNAVAILABLE;
192 - (OFData *)messagePackRepresentation OF_UNAVAILABLE;
193 @end
194 
195 OF_ASSUME_NONNULL_END
A class for storing arbitrary data in an array.
Definition: OFData.h:40
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:132
A class for parsing URLs and accessing parts of it.
Definition: OFURL.h:34
A class which stores an XML element.
Definition: OFXMLElement.h:34