IconGenerator doesn't guarantee the hash size / quantity
wainglaister opened this issue · 4 comments
IconGenerator performs a simple conversion of the hash data into a digits array - but there is no guarantee that the size of that array will be suitable for use in selectColors
as the size is determined only by the hash with no default minimum. As it seems only around 12 digits are required then there is also no reason to process the whole hash if it's large.
Perhaps:
var digits = [UInt8](repeating: 0, count: requiredIndex)
var index = 0
for byte in hash {
digits[index] = (byte & 0xf0) >> 4
digits[index+1] = byte & 0x0f
index += 2
if index >= requiredIndex { break }
}
when my string's length < 6 ,it crashed,
I see Android code,there exists some different ,https://github.com/WycliffeAssociates/jdenticon-kotlin/blob/master/src/main/kotlin/jdenticon/IconGenerator.kt
so there is any good solution for this question for iOS ?
thanks!!
Thanks, that PR should fix it.
oh thanks!👍
but another question,did you have a try,when use Android code (https://github.com/WycliffeAssociates/jdenticon-kotlin/blob/master/src/main/kotlin/jdenticon/IconGenerator.kt) and iOS swift code to generate an Icon picture with the same string,eg "testios123", but the icon is different,it feels strange,any ideas ?
thanks !
I'm not familiar with the Android implementation, but I made this version so that it matches the original JavaScript one.