diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2018-06-02 12:35:11 +0530 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-02 19:12:30 +0200 |
commit | 4986d92f3d5fb0d7bb4f15bf2b02f8b36ef23dff (patch) | |
tree | d9f3e20f7fd55ca9f5e8f6647836601659f45168 /app/src/main/java/com/wireguard/crypto/KeyEncoding.java | |
parent | 0b1c7cc35f68ce540b54eda3553a6ca6d4c3b347 (diff) |
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>
Diffstat (limited to 'app/src/main/java/com/wireguard/crypto/KeyEncoding.java')
-rw-r--r-- | app/src/main/java/com/wireguard/crypto/KeyEncoding.java | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/app/src/main/java/com/wireguard/crypto/KeyEncoding.java b/app/src/main/java/com/wireguard/crypto/KeyEncoding.java index 1f32cc52..6bf8bcb5 100644 --- a/app/src/main/java/com/wireguard/crypto/KeyEncoding.java +++ b/app/src/main/java/com/wireguard/crypto/KeyEncoding.java @@ -25,10 +25,10 @@ public final class KeyEncoding { // 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; for (int i = 0; i < 4; ++i) { - final char c = src[i + src_offset]; + final char c = src[i + srcOffset]; val |= (-1 + ((((('A' - 1) - c) & (c - ('Z' + 1))) >>> 8) & (c - 64)) + ((((('a' - 1) - c) & (c - ('z' + 1))) >>> 8) & (c - 70)) @@ -40,16 +40,16 @@ public final class KeyEncoding { return val; } - private static void encodeBase64(final byte[] src, final int src_offset, - final char[] dest, final int dest_offset) { + private static void encodeBase64(final byte[] src, final int srcOffset, + final char[] dest, final int destOffset) { final byte[] input = { - (byte) ((src[src_offset] >>> 2) & 63), - (byte) ((src[src_offset] << 4 | ((src[1 + src_offset] & 0xff) >>> 4)) & 63), - (byte) ((src[1 + src_offset] << 2 | ((src[2 + src_offset] & 0xff) >>> 6)) & 63), - (byte) ((src[2 + src_offset]) & 63), + (byte) ((src[srcOffset] >>> 2) & 63), + (byte) ((src[srcOffset] << 4 | ((src[1 + srcOffset] & 0xff) >>> 4)) & 63), + (byte) ((src[1 + srcOffset] << 2 | ((src[2 + srcOffset] & 0xff) >>> 6)) & 63), + (byte) ((src[2 + srcOffset]) & 63), }; 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) - (((51 - input[i]) >>> 8) & 75) - (((61 - input[i]) >>> 8) & 15) @@ -62,7 +62,8 @@ public final class KeyEncoding { final byte[] key = new byte[KEY_LENGTH]; if (input.length != KEY_LENGTH_BASE64 || input[KEY_LENGTH_BASE64 - 1] != '=') 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) { final int val = decodeBase64(input, i * 4); ret |= val >>> 31; @@ -94,25 +95,31 @@ public final class KeyEncoding { int ret = 0; 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_num = c ^ 48; - c_num0 = ((c_num - 10) >>> 8) & 0xff; - c_alpha = (c & ~32) - 55; - c_alpha0 = (((c_alpha - 10) ^ (c_alpha - 16)) >>> 8) & 0xff; - ret |= ((c_num0 | c_alpha0) - 1) >>> 8; - c_val = (c_num0 & c_num) | (c_alpha0 & c_alpha); - c_acc = c_val * 16; + cNum = c ^ 48; + cNum0 = ((cNum - 10) >>> 8) & 0xff; + cAlpha = (c & ~32) - 55; + cAlpha0 = (((cAlpha - 10) ^ (cAlpha - 16)) >>> 8) & 0xff; + ret |= ((cNum0 | cAlpha0) - 1) >>> 8; + cVal = (cNum0 & cNum) | (cAlpha0 & cAlpha); + cAcc = cVal * 16; c = input[i + 1]; - c_num = c ^ 48; - c_num0 = ((c_num - 10) >>> 8) & 0xff; - c_alpha = (c & ~32) - 55; - c_alpha0 = (((c_alpha - 10) ^ (c_alpha - 16)) >>> 8) & 0xff; - ret |= ((c_num0 | c_alpha0) - 1) >>> 8; - c_val = (c_num0 & c_num) | (c_alpha0 & c_alpha); - key[i / 2] = (byte) (c_acc | c_val); + cNum = c ^ 48; + cNum0 = ((cNum - 10) >>> 8) & 0xff; + cAlpha = (c & ~32) - 55; + cAlpha0 = (((cAlpha - 10) ^ (cAlpha - 16)) >>> 8) & 0xff; + ret |= ((cNum0 | cAlpha0) - 1) >>> 8; + cVal = (cNum0 & cNum) | (cAlpha0 & cAlpha); + key[i / 2] = (byte) (cAcc | cVal); } if (ret != 0) throw new IllegalArgumentException(KEY_LENGTH_HEX_EXCEPTION_MESSAGE); |