fix(core): NSData+String: Dont mix tabs and spaces

This commit is contained in:
Nicolas Höft 2020-05-03 15:13:44 +02:00 committed by Nicolas Höft
parent 3040c275d8
commit 562f81f21f

View file

@ -175,7 +175,7 @@ static void _nettle_md5_compress(uint32_t *digest, const uint8_t *input);
*
* @param passwordScheme The scheme to use for hashing/encryption.
* @param theSalt The salt to be used. If none is given but needed, it will be generated
* @return Binary data from the encryption by the specified scheme. On error the funciton returns nil.
* @return Binary data from the encryption by the specified scheme. On error the function returns nil.
*/
- (NSData *) asCryptedPassUsingScheme: (NSString *) passwordScheme
withSalt: (NSData *) theSalt
@ -780,15 +780,16 @@ static void _nettle_md5_compress(uint32_t *digest, const uint8_t *input);
// for the ssha schemes the salt is appended at the endif
// so the range with the salt are bytes after each digest length
if ([theScheme caseInsensitiveCompare: @"crypt"] == NSOrderedSame)
if ([theScheme caseInsensitiveCompare: @"crypt"] == NSOrderedSame ||
[theScheme caseInsensitiveCompare: @"blf-crypt"] == NSOrderedSame)
{
// for crypt schemes simply use the whole string
// for (blf-)crypt schemes simply use the whole string
// the crypt() function is able to extract it by itself
r = NSMakeRange(0, len);
}
else if ([theScheme caseInsensitiveCompare: @"md5-crypt"] == NSOrderedSame ||
[theScheme caseInsensitiveCompare: @"sha256-crypt"] == NSOrderedSame ||
[theScheme caseInsensitiveCompare: @"sha512-crypt"] == NSOrderedSame)
[theScheme caseInsensitiveCompare: @"sha256-crypt"] == NSOrderedSame ||
[theScheme caseInsensitiveCompare: @"sha512-crypt"] == NSOrderedSame)
{
// md5-crypt is generated the following "$1$<salt>$<encrypted pass>"
// sha256-crypt is generated the following "$5$<salt>$<encrypted pass>"
@ -807,21 +808,21 @@ static void _nettle_md5_compress(uint32_t *digest, const uint8_t *input);
}
// second is the identifier of md5-crypt/sha256-crypt or sha512-crypt
else if ([[cryptParts objectAtIndex: 1] caseInsensitiveCompare: @"1"] == NSOrderedSame ||
[[cryptParts objectAtIndex: 1] caseInsensitiveCompare: @"5"] == NSOrderedSame ||
[[cryptParts objectAtIndex: 1] caseInsensitiveCompare: @"6"] == NSOrderedSame)
[[cryptParts objectAtIndex: 1] caseInsensitiveCompare: @"5"] == NSOrderedSame ||
[[cryptParts objectAtIndex: 1] caseInsensitiveCompare: @"6"] == NSOrderedSame)
{
// third is the salt; convert it to NSData
if ([cryptParts count] == 4)
return [[cryptParts objectAtIndex: 2] dataUsingEncoding: NSUTF8StringEncoding];
else
{
NSString *saltWithRounds;
// third is the salt; convert it to NSData
if ([cryptParts count] == 4)
return [[cryptParts objectAtIndex: 2] dataUsingEncoding: NSUTF8StringEncoding];
else
{
NSString *saltWithRounds;
saltWithRounds = [NSString stringWithFormat: @"%@$%@", [cryptParts objectAtIndex: 2], [cryptParts objectAtIndex: 3]];
saltWithRounds = [NSString stringWithFormat: @"%@$%@", [cryptParts objectAtIndex: 2], [cryptParts objectAtIndex: 3]];
return [saltWithRounds dataUsingEncoding: NSUTF8StringEncoding];
}
}
return [saltWithRounds dataUsingEncoding: NSUTF8StringEncoding];
}
}
// nothing good
return [NSData data];
}