crypto: KeyEncoding: Fix style
- Replace python style variable names with camel case - Don't declare multiple variables in the same line Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
0b1c7cc35f
commit
4986d92f3d
@ -25,10 +25,10 @@ public final class KeyEncoding {
|
|||||||
// Prevent instantiation.
|
// Prevent instantiation.
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int decodeBase64(final char[] src, final int src_offset) {
|
private static int decodeBase64(final char[] src, final int srcOffset) {
|
||||||
int val = 0;
|
int val = 0;
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
final char c = src[i + src_offset];
|
final char c = src[i + srcOffset];
|
||||||
val |= (-1
|
val |= (-1
|
||||||
+ ((((('A' - 1) - c) & (c - ('Z' + 1))) >>> 8) & (c - 64))
|
+ ((((('A' - 1) - c) & (c - ('Z' + 1))) >>> 8) & (c - 64))
|
||||||
+ ((((('a' - 1) - c) & (c - ('z' + 1))) >>> 8) & (c - 70))
|
+ ((((('a' - 1) - c) & (c - ('z' + 1))) >>> 8) & (c - 70))
|
||||||
@ -40,16 +40,16 @@ public final class KeyEncoding {
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void encodeBase64(final byte[] src, final int src_offset,
|
private static void encodeBase64(final byte[] src, final int srcOffset,
|
||||||
final char[] dest, final int dest_offset) {
|
final char[] dest, final int destOffset) {
|
||||||
final byte[] input = {
|
final byte[] input = {
|
||||||
(byte) ((src[src_offset] >>> 2) & 63),
|
(byte) ((src[srcOffset] >>> 2) & 63),
|
||||||
(byte) ((src[src_offset] << 4 | ((src[1 + src_offset] & 0xff) >>> 4)) & 63),
|
(byte) ((src[srcOffset] << 4 | ((src[1 + srcOffset] & 0xff) >>> 4)) & 63),
|
||||||
(byte) ((src[1 + src_offset] << 2 | ((src[2 + src_offset] & 0xff) >>> 6)) & 63),
|
(byte) ((src[1 + srcOffset] << 2 | ((src[2 + srcOffset] & 0xff) >>> 6)) & 63),
|
||||||
(byte) ((src[2 + src_offset]) & 63),
|
(byte) ((src[2 + srcOffset]) & 63),
|
||||||
};
|
};
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
dest[i + dest_offset] = (char) (input[i] + 'A'
|
dest[i + destOffset] = (char) (input[i] + 'A'
|
||||||
+ (((25 - input[i]) >>> 8) & 6)
|
+ (((25 - input[i]) >>> 8) & 6)
|
||||||
- (((51 - input[i]) >>> 8) & 75)
|
- (((51 - input[i]) >>> 8) & 75)
|
||||||
- (((61 - input[i]) >>> 8) & 15)
|
- (((61 - input[i]) >>> 8) & 15)
|
||||||
@ -62,7 +62,8 @@ public final class KeyEncoding {
|
|||||||
final byte[] key = new byte[KEY_LENGTH];
|
final byte[] key = new byte[KEY_LENGTH];
|
||||||
if (input.length != KEY_LENGTH_BASE64 || input[KEY_LENGTH_BASE64 - 1] != '=')
|
if (input.length != KEY_LENGTH_BASE64 || input[KEY_LENGTH_BASE64 - 1] != '=')
|
||||||
throw new IllegalArgumentException(KEY_LENGTH_BASE64_EXCEPTION_MESSAGE);
|
throw new IllegalArgumentException(KEY_LENGTH_BASE64_EXCEPTION_MESSAGE);
|
||||||
int i, ret = 0;
|
int i;
|
||||||
|
int ret = 0;
|
||||||
for (i = 0; i < KEY_LENGTH / 3; ++i) {
|
for (i = 0; i < KEY_LENGTH / 3; ++i) {
|
||||||
final int val = decodeBase64(input, i * 4);
|
final int val = decodeBase64(input, i * 4);
|
||||||
ret |= val >>> 31;
|
ret |= val >>> 31;
|
||||||
@ -94,25 +95,31 @@ public final class KeyEncoding {
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
for (int i = 0; i < KEY_LENGTH_HEX; i += 2) {
|
for (int i = 0; i < KEY_LENGTH_HEX; i += 2) {
|
||||||
int c, c_num, c_num0, c_alpha, c_alpha0, c_val, c_acc;
|
int c;
|
||||||
|
int cNum;
|
||||||
|
int cNum0;
|
||||||
|
int cAlpha;
|
||||||
|
int cAlpha0;
|
||||||
|
int cVal;
|
||||||
|
final int cAcc;
|
||||||
|
|
||||||
c = input[i];
|
c = input[i];
|
||||||
c_num = c ^ 48;
|
cNum = c ^ 48;
|
||||||
c_num0 = ((c_num - 10) >>> 8) & 0xff;
|
cNum0 = ((cNum - 10) >>> 8) & 0xff;
|
||||||
c_alpha = (c & ~32) - 55;
|
cAlpha = (c & ~32) - 55;
|
||||||
c_alpha0 = (((c_alpha - 10) ^ (c_alpha - 16)) >>> 8) & 0xff;
|
cAlpha0 = (((cAlpha - 10) ^ (cAlpha - 16)) >>> 8) & 0xff;
|
||||||
ret |= ((c_num0 | c_alpha0) - 1) >>> 8;
|
ret |= ((cNum0 | cAlpha0) - 1) >>> 8;
|
||||||
c_val = (c_num0 & c_num) | (c_alpha0 & c_alpha);
|
cVal = (cNum0 & cNum) | (cAlpha0 & cAlpha);
|
||||||
c_acc = c_val * 16;
|
cAcc = cVal * 16;
|
||||||
|
|
||||||
c = input[i + 1];
|
c = input[i + 1];
|
||||||
c_num = c ^ 48;
|
cNum = c ^ 48;
|
||||||
c_num0 = ((c_num - 10) >>> 8) & 0xff;
|
cNum0 = ((cNum - 10) >>> 8) & 0xff;
|
||||||
c_alpha = (c & ~32) - 55;
|
cAlpha = (c & ~32) - 55;
|
||||||
c_alpha0 = (((c_alpha - 10) ^ (c_alpha - 16)) >>> 8) & 0xff;
|
cAlpha0 = (((cAlpha - 10) ^ (cAlpha - 16)) >>> 8) & 0xff;
|
||||||
ret |= ((c_num0 | c_alpha0) - 1) >>> 8;
|
ret |= ((cNum0 | cAlpha0) - 1) >>> 8;
|
||||||
c_val = (c_num0 & c_num) | (c_alpha0 & c_alpha);
|
cVal = (cNum0 & cNum) | (cAlpha0 & cAlpha);
|
||||||
key[i / 2] = (byte) (c_acc | c_val);
|
key[i / 2] = (byte) (cAcc | cVal);
|
||||||
}
|
}
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
throw new IllegalArgumentException(KEY_LENGTH_HEX_EXCEPTION_MESSAGE);
|
throw new IllegalArgumentException(KEY_LENGTH_HEX_EXCEPTION_MESSAGE);
|
||||||
|
Loading…
Reference in New Issue
Block a user