Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8ca757
commit bfbfd63
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
presto-main/src/main/java/com/facebook/presto/operator/scalar/HmacFunctions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.operator.scalar; | ||
|
||
import com.facebook.presto.spi.function.Description; | ||
import com.facebook.presto.spi.function.ScalarFunction; | ||
import com.facebook.presto.spi.function.SqlType; | ||
import com.facebook.presto.spi.type.StandardTypes; | ||
import com.google.common.hash.Hashing; | ||
import io.airlift.slice.Slice; | ||
|
||
import static io.airlift.slice.Slices.wrappedBuffer; | ||
|
||
public final class HmacFunctions | ||
{ | ||
private HmacFunctions() {} | ||
|
||
@Description("Compute HMAC with MD5") | ||
@ScalarFunction | ||
@SqlType(StandardTypes.VARBINARY) | ||
public static Slice hmacMd5(@SqlType(StandardTypes.VARBINARY) Slice slice, @SqlType(StandardTypes.VARBINARY) Slice key) | ||
{ | ||
return wrappedBuffer(Hashing.hmacMd5(key.getBytes()).hashBytes(slice.getBytes()).asBytes()); | ||
} | ||
|
||
@Description("Compute HMAC with SHA1") | ||
@ScalarFunction | ||
@SqlType(StandardTypes.VARBINARY) | ||
public static Slice hmacSha1(@SqlType(StandardTypes.VARBINARY) Slice slice, @SqlType(StandardTypes.VARBINARY) Slice key) | ||
{ | ||
return wrappedBuffer(Hashing.hmacSha1(key.getBytes()).hashBytes(slice.getBytes()).asBytes()); | ||
} | ||
|
||
@Description("Compute HMAC with SHA256") | ||
@ScalarFunction | ||
@SqlType(StandardTypes.VARBINARY) | ||
public static Slice hmacSha256(@SqlType(StandardTypes.VARBINARY) Slice slice, @SqlType(StandardTypes.VARBINARY) Slice key) | ||
{ | ||
return wrappedBuffer(Hashing.hmacSha256(key.getBytes()).hashBytes(slice.getBytes()).asBytes()); | ||
} | ||
|
||
@Description("Compute HMAC with SHA512") | ||
@ScalarFunction | ||
@SqlType(StandardTypes.VARBINARY) | ||
public static Slice hmacSha512(@SqlType(StandardTypes.VARBINARY) Slice slice, @SqlType(StandardTypes.VARBINARY) Slice key) | ||
{ | ||
return wrappedBuffer(Hashing.hmacSha512(key.getBytes()).hashBytes(slice.getBytes()).asBytes()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters