41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
OF_APPLICATION_DELEGATE(OFHash)
static void
help(void)
{
[OFStdErr writeLine: OF_LOCALIZED(@"usage",
@"Usage: %[prog] [--md5] [--ripemd160] [--sha1] [--sha224] "
@"[--sha256] [--sha384] [--sha512] file1 [file2 ...]",
@"prog", [OFApplication programName])];
[OFApplication terminateWithStatus: 1];
}
static void
printHash(OFString *algo, OFString *path, id <OFCryptographicHash> hash)
|
|
|
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
OF_APPLICATION_DELEGATE(OFHash)
static void
help(void)
{
[OFStdErr writeLine: OF_LOCALIZED(@"usage",
@"Usage: %[prog] [--md5] [--ripemd160] [--sha1] [--sha224] "
@"[--sha256] [--sha384] [--sha512] [--iri] file1 [file2 ...]",
@"prog", [OFApplication programName])];
[OFApplication terminateWithStatus: 1];
}
static void
printHash(OFString *algo, OFString *path, id <OFCryptographicHash> hash)
|
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
}
@implementation OFHash
- (void)applicationDidFinishLaunching: (OFNotification *)notification
{
int exitStatus = 0;
bool calculateMD5, calculateRIPEMD160, calculateSHA1, calculateSHA224;
bool calculateSHA256, calculateSHA384, calculateSHA512;
const OFOptionsParserOption options[] = {
{ '\0', @"md5", 0, &calculateMD5, NULL },
{ '\0', @"ripemd160", 0, &calculateRIPEMD160, NULL },
{ '\0', @"sha1", 0, &calculateSHA1, NULL },
{ '\0', @"sha224", 0, &calculateSHA224, NULL },
{ '\0', @"sha256", 0, &calculateSHA256, NULL },
{ '\0', @"sha384", 0, &calculateSHA384, NULL },
{ '\0', @"sha512", 0, &calculateSHA512, NULL },
{ '\0', nil, 0, NULL, NULL }
};
OFOptionsParser *optionsParser =
[OFOptionsParser parserWithOptions: options];
OFUnichar option;
OFMD5Hash *MD5Hash = nil;
OFRIPEMD160Hash *RIPEMD160Hash = nil;
|
|
>
|
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
}
@implementation OFHash
- (void)applicationDidFinishLaunching: (OFNotification *)notification
{
int exitStatus = 0;
bool calculateMD5, calculateRIPEMD160, calculateSHA1, calculateSHA224;
bool calculateSHA256, calculateSHA384, calculateSHA512, isIRI;
const OFOptionsParserOption options[] = {
{ '\0', @"md5", 0, &calculateMD5, NULL },
{ '\0', @"ripemd160", 0, &calculateRIPEMD160, NULL },
{ '\0', @"sha1", 0, &calculateSHA1, NULL },
{ '\0', @"sha224", 0, &calculateSHA224, NULL },
{ '\0', @"sha256", 0, &calculateSHA256, NULL },
{ '\0', @"sha384", 0, &calculateSHA384, NULL },
{ '\0', @"sha512", 0, &calculateSHA512, NULL },
{ '\0', @"iri", 0, &isIRI, NULL },
{ '\0', nil, 0, NULL, NULL }
};
OFOptionsParser *optionsParser =
[OFOptionsParser parserWithOptions: options];
OFUnichar option;
OFMD5Hash *MD5Hash = nil;
OFRIPEMD160Hash *RIPEMD160Hash = nil;
|
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
|
if (calculateSHA512)
SHA512Hash = [OFSHA512Hash hashWithAllowsSwappableMemory: true];
for (OFString *path in optionsParser.remainingArguments) {
void *pool = objc_autoreleasePoolPush();
OFStream *file;
if ([path isEqual: @"-"])
file = OFStdIn;
else {
@try {
file = [OFFile fileWithPath: path mode: @"r"];
} @catch (OFOpenItemFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror(e.errNo)
encoding: [OFLocale encoding]];
[OFStdErr writeLine: OF_LOCALIZED(
@"failed_to_open_file",
@"Failed to open file %[file]: %[error]",
@"file", e.path,
@"error", error)];
exitStatus = 1;
goto outer_loop_end;
}
}
|
|
>
>
>
>
>
>
>
>
|
>
>
>
|
|
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
|
if (calculateSHA512)
SHA512Hash = [OFSHA512Hash hashWithAllowsSwappableMemory: true];
for (OFString *path in optionsParser.remainingArguments) {
void *pool = objc_autoreleasePoolPush();
OFStream *file;
if (!isIRI && [path isEqual: @"-"])
file = OFStdIn;
else {
@try {
if (isIRI) {
OFIRI *IRI =
[OFIRI IRIWithString: path];
file = [OFIRIHandler
openItemAtIRI: IRI
mode: @"r"];
} else
file = [OFFile fileWithPath: path
mode: @"r"];
} @catch (OFOpenItemFailedException *e) {
OFString *error = [OFString
stringWithCString: strerror(e.errNo)
encoding: [OFLocale encoding]];
OFString *filePath =
(e.IRI != nil ? e.IRI.string : e.path);
[OFStdErr writeLine: OF_LOCALIZED(
@"failed_to_open_file",
@"Failed to open file %[file]: %[error]",
@"file", filePath,
@"error", error)];
exitStatus = 1;
goto outer_loop_end;
}
}
|