Implement Base64 without need of JDK8. (#78)
This commit is contained in:
+1
-8
@@ -116,14 +116,7 @@ internal interface ContextUtils {
|
|||||||
*/
|
*/
|
||||||
val String.globalHashBase64: String
|
val String.globalHashBase64: String
|
||||||
get() {
|
get() {
|
||||||
val bytes = this.toByteArray(Charsets.UTF_8)
|
return base64Encode(globalHashBytes)
|
||||||
val hashBytes = this.globalHashBytes
|
|
||||||
|
|
||||||
val base64Bytes = java.util.Base64.getEncoder().encode(globalHashBytes)
|
|
||||||
// TODO: do not use JRE for base64
|
|
||||||
// (it is impossible right now due to native interop limitations)
|
|
||||||
|
|
||||||
return String(base64Bytes, Charsets.US_ASCII)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+11
@@ -21,4 +21,15 @@ internal fun globalHash(data: ByteArray, retValPlacement: Placement): GlobalHash
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun base64Encode(data: ByteArray): String {
|
||||||
|
memScoped {
|
||||||
|
val resultSize = 4 * data.size / 3 + 3 + 1
|
||||||
|
val result = alloc(NativeArray of Int8Box length resultSize)
|
||||||
|
val bytes = allocNativeArrayOf(data)
|
||||||
|
Base64Encode(bytes.ptr, data.size, result.ptr, resultSize)
|
||||||
|
// TODO: any better way to do that without two copies?
|
||||||
|
return CString.fromArray(result).toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal class LocalHash(val value: Long) : ConstValue by Int64(value)
|
internal class LocalHash(val value: Long) : ConstValue by Int64(value)
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int Base64Encode(
|
int Base64Encode(
|
||||||
const void* dataBuf, uint32_t dataLength, char* result, uint32_t resultSize) {
|
const void* dataBuf, uint32_t dataLength, void* resultBuf, uint32_t resultSize) {
|
||||||
|
char *result = reinterpret_cast<char*>(resultBuf);
|
||||||
const uint8_t *data = reinterpret_cast<const uint8_t*>(dataBuf);
|
const uint8_t *data = reinterpret_cast<const uint8_t*>(dataBuf);
|
||||||
size_t resultIndex = 0;
|
size_t resultIndex = 0;
|
||||||
size_t x;
|
size_t x;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int Base64Encode(
|
int Base64Encode(
|
||||||
const void* input, uint32_t inputLen, char* output, uint32_t outputLen);
|
const void* input, uint32_t inputLen, void* output, uint32_t outputLen);
|
||||||
|
|
||||||
int Base64Decode(
|
int Base64Decode(
|
||||||
const char* input, uint32_t inputLen, void* output, uint32_t* outputLen);
|
const char* input, uint32_t inputLen, void* output, uint32_t* outputLen);
|
||||||
|
|||||||
Reference in New Issue
Block a user