objective c - Why get a partial data range with subdataWithRange crashes? -



objective c - Why get a partial data range with subdataWithRange crashes? -

i have code:

nsmutabledata *derivedkey = [nsmutabledata datawithlength:32]; // code missing..fill somehow derivedkey 32 random bytes // line doesn't crash nsdata *iv = [derivedkey subdatawithrange:nsmakerange(0, 32)];

..

// line crashes nsdata *iv = [derivedkey subdatawithrange:nsmakerange(16, 32)];

any suggestion why happens ? seems somehow whole range 0 - 32 passes wanna simple new nsdata variable contains sec half of bytes

it crashes, because sec parameter of nsrangemake length of range. trying take 32 bytes starting offset 16, exceeds info size (final byte 48 in order).

so simply, alter to:

nsdata *iv = [derivedkey subdatawithrange:nsmakerange(16, 16)];

check ref: http://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/miscellaneous/foundation_functions/reference/reference.html#//apple_ref/c/func/nsmakerange

objective-c

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -