1 | /* |
2 | * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"). |
5 | * You may not use this file except in compliance with the License. |
6 | * A copy of the License is located at |
7 | * |
8 | * http://aws.amazon.com/apache2.0 |
9 | * |
10 | * or in the "license" file accompanying this file. This file is distributed |
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
12 | * express or implied. See the License for the specific language governing |
13 | * permissions and limitations under the License. |
14 | */ |
15 | #ifdef BUILD_JNI_BINDINGS |
16 | # include <aws/checksums/crc.h> |
17 | # include <aws/checksums/crc_jni.h> |
18 | |
19 | jint JNICALL Java_software_amazon_awschecksums_AWSCRC32C_crc32c( |
20 | JNIEnv *env, |
21 | jobject obj, |
22 | jbyteArray data, |
23 | jint offset, |
24 | jint length, |
25 | jint previous_crc) { |
26 | jbyte *buffer_ptr = (*env)->GetPrimitiveArrayCritical(env, data, 0); |
27 | int ret_val = (int)aws_checksums_crc32c((const uint8_t *)(buffer_ptr + offset), length, previous_crc); |
28 | (*env)->ReleasePrimitiveArrayCritical(env, data, buffer_ptr, 0); |
29 | |
30 | return ret_val; |
31 | } |
32 | |
33 | jint JNICALL Java_software_amazon_awschecksums_AWSCRC32C_crc32cDirect( |
34 | JNIEnv *env, |
35 | jobject obj, |
36 | jobject data, |
37 | jint offset, |
38 | jint length, |
39 | jint previous_crc) { |
40 | jbyte *buf_ptr = (*env)->GetDirectBufferAddress(env, data); |
41 | return aws_checksums_crc32c((const uint8_t *)(buf_ptr + offset), length, previous_crc); |
42 | } |
43 | |
44 | jint JNICALL Java_software_amazon_awschecksums_AWSCRC32_crc32( |
45 | JNIEnv *env, |
46 | jobject obj, |
47 | jbyteArray data, |
48 | jint offset, |
49 | jint length, |
50 | jint previous_crc) { |
51 | jbyte *buffer_ptr = (*env)->GetPrimitiveArrayCritical(env, data, 0); |
52 | int ret_val = (int)aws_checksums_crc32((const uint8_t *)(buffer_ptr + offset), length, previous_crc); |
53 | (*env)->ReleasePrimitiveArrayCritical(env, data, buffer_ptr, 0); |
54 | |
55 | return ret_val; |
56 | } |
57 | |
58 | jint JNICALL Java_software_amazon_awschecksums_AWSCRC32_crc32Direct( |
59 | JNIEnv *env, |
60 | jobject obj, |
61 | jobject data, |
62 | jint offset, |
63 | jint length, |
64 | jint previous_crc) { |
65 | jbyte *buf_ptr = (*env)->GetDirectBufferAddress(env, data); |
66 | return aws_checksums_crc32((const uint8_t *)(buf_ptr + offset), length, previous_crc); |
67 | } |
68 | |
69 | #endif |
70 | |