24 package org.lightjason.agentspeak.action.builtin.crypto;
26 import com.google.common.hash.Hashing;
27 import com.google.common.io.BaseEncoding;
28 import org.apache.commons.lang3.SerializationUtils;
38 import javax.annotation.Nonnegative;
39 import javax.annotation.Nonnull;
40 import java.io.Serializable;
41 import java.io.UnsupportedEncodingException;
42 import java.security.MessageDigest;
43 import java.security.NoSuchAlgorithmException;
44 import java.util.List;
45 import java.util.Locale;
82 @Nonnull
final List<ITerm> p_argument, @Nonnull
final List<ITerm> p_return
87 .map( i ->
hash( p_context, p_argument.get( 0 ).<String>raw(),
serialize( p_context, i ) ) )
89 .forEach( p_return::add );
108 return CCommon.rawvalueAssignableTo( p_object, String.class )
109 ? p_object.<String>raw().getBytes(
"UTF-8" )
110 : SerializationUtils.serialize( p_object.<Serializable>raw() );
112 catch (
final UnsupportedEncodingException l_exception )
126 private static String
hash( @Nonnull
final IContext p_context, @Nonnull
final String p_algorithm, @Nonnull
final byte[] p_data )
128 switch ( p_algorithm.trim().toLowerCase( Locale.ROOT ) )
131 return Hashing.adler32().newHasher().putBytes( p_data ).hash().toString();
134 return Hashing.crc32().newHasher().putBytes( p_data ).hash().toString();
137 return Hashing.crc32c().newHasher().putBytes( p_data ).hash().toString();
140 return Hashing.murmur3_32().newHasher().putBytes( p_data ).hash().toString();
143 return Hashing.murmur3_128().newHasher().putBytes( p_data ).hash().toString();
146 return Hashing.sipHash24().newHasher().putBytes( p_data ).hash().toString();
151 return BaseEncoding.base16().encode( MessageDigest.getInstance( p_algorithm ).digest( p_data ) ).toLowerCase( Locale.ROOT );
153 catch (
final NoSuchAlgorithmException l_exception )
base class of build-in actions for setting name by package/classname (without prefix character) ...
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
static byte [] serialize( @Nonnull final IContext p_context, @Nonnull final ITerm p_object)
serialize data
common structure for execution definition
static String hash( @Nonnull final IContext p_context, @Nonnull final String p_algorithm, @Nonnull final byte[] p_data)
runs hashing function with difference between Google Guava hashing and Java default digest ...
execution context with local data
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
result for an immutable fuzzy value
final int minimalArgumentNumber()
minimum number of arguments
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
class for any helper calls
static final long serialVersionUID
serial id
term structure for simple datatypes