ObjFW  Diff

Differences From Artifact [b27fb7f5ab]:

To Artifact [c8c16d0702]:


88
89
90
91
92
93
94
95
96
97



98
99
100
101
102
103
104
88
89
90
91
92
93
94



95
96
97
98
99
100
101
102
103
104







-
-
-
+
+
+







	 * be used in the end, this is enough secure memory.
	 */
	[OFSecureData preallocateMemoryWithSize:
	    class_getInstanceSize([OFSHA512Hash class])];

	sandbox = [[OFSandbox alloc] init];
	@try {
		[sandbox setAllowsStdIO: true];
		[sandbox setAllowsReadingFiles: true];
		[sandbox setAllowsUserDatabaseReading: true];
		sandbox.allowsStdIO = true;
		sandbox.allowsReadingFiles = true;
		sandbox.allowsUserDatabaseReading = true;

		for (OFString *path in arguments) {
			if (first) {
				first = false;
				continue;
			}

118
119
120
121
122
123
124
125

126
127
128

129
130
131
132
133
134
135
118
119
120
121
122
123
124

125
126
127

128
129
130
131
132
133
134
135







-
+


-
+








#ifndef OF_AMIGAOS
	[OFLocale addLanguageDirectory: @LANGUAGE_DIR];
#else
	[OFLocale addLanguageDirectory: @"PROGDIR:/share/ofhash/lang"];
#endif

	if ([arguments count] < 2)
	if (arguments.count < 2)
		help();

	if ((hash = hashForName([arguments firstObject])) == nil)
	if ((hash = hashForName(arguments.firstObject)) == nil)
		help();

	for (OFString *path in arguments) {
		void *pool;
		OFStream *file;
		const uint8_t *digest;
		size_t digestSize;
145
146
147
148
149
150
151
152

153
154
155
156
157
158

159
160
161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197


198
199
200
201
202
203
204
205
206
207
208
209
210
145
146
147
148
149
150
151

152
153
154
155
156
157

158
159
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175
176

177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195


196
197
198
199
200
201
202
203
204
205
206
207
208
209
210







-
+





-
+









-
+








-
+


















-
-
+
+













			file = of_stdin;
		else {
			@try {
				file = [OFFile fileWithPath: path
						       mode: @"r"];
			} @catch (OFOpenItemFailedException *e) {
				OFString *error = [OFString
				    stringWithCString: strerror([e errNo])
				    stringWithCString: strerror(e.errNo)
					     encoding: [OFLocale encoding]];

				[of_stderr writeLine: OF_LOCALIZED(
				    @"failed_to_open_file",
				    @"Failed to open file %[file]: %[error]",
				    @"file", [e path],
				    @"file", e.path,
				    @"error", error)];

				exitStatus = 1;
				goto outer_loop_end;
			}
		}

		[hash reset];

		while (![file isAtEndOfStream]) {
		while (!file.atEndOfStream) {
			uint8_t buffer[1024];
			size_t length;

			@try {
				length = [file readIntoBuffer: buffer
						       length: 1024];
			} @catch (OFReadFailedException *e) {
				OFString *error = [OFString
				    stringWithCString: strerror([e errNo])
				    stringWithCString: strerror(e.errNo)
					     encoding: [OFLocale encoding]];

				[of_stderr writeLine: OF_LOCALIZED(
				    @"failed_to_read_file",
				    @"Failed to read %[file]: %[error]",
				    @"file", path,
				    @"error", error)];

				exitStatus = 1;
				goto outer_loop_end;
			}

			[hash updateWithBuffer: buffer
					length: length];
		}

		[file close];

		digest = [hash digest];
		digestSize = [[hash class] digestSize];
		digest = hash.digest;
		digestSize = hash.digestSize;

		for (size_t i = 0; i < digestSize; i++)
			[of_stdout writeFormat: @"%02x", digest[i]];

		[of_stdout writeFormat: @"  %@\n", path];

outer_loop_end:
		objc_autoreleasePoolPop(pool);
	}

	[OFApplication terminateWithStatus: exitStatus];
}
@end