mirror of
https://github.com/fluencelabs/crypto
synced 2025-04-24 14:22:18 +00:00
Kad proto cross (#73)
* Kademlia-protocol cross build * test:compile error fixed * CryptoHashers
This commit is contained in:
parent
d091146dd2
commit
01eb2abec9
24
js/src/main/scala/fluence/crypto/hash/CryptoHashers.scala
Normal file
24
js/src/main/scala/fluence/crypto/hash/CryptoHashers.scala
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Fluence Labs Limited
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package fluence.crypto.hash
|
||||
|
||||
object CryptoHashers {
|
||||
lazy val Sha1: CryptoHasher.Bytes = JsCryptoHasher.Sha1
|
||||
|
||||
lazy val Sha256: CryptoHasher.Bytes = JsCryptoHasher.Sha256
|
||||
}
|
@ -24,7 +24,7 @@ import scala.scalajs.js.JSConverters._
|
||||
|
||||
object JsCryptoHasher {
|
||||
|
||||
lazy val Sha256: CryptoHasher[Array[Byte], Array[Byte]] = new CryptoHasher[Array[Byte], Array[Byte]] {
|
||||
lazy val Sha256: CryptoHasher.Bytes = new CryptoHasher[Array[Byte], Array[Byte]] {
|
||||
override def hash(msg1: Array[Byte]): Array[Byte] = {
|
||||
val sha256 = new SHA256()
|
||||
sha256.update(msg1.toJSArray)
|
||||
@ -35,7 +35,7 @@ object JsCryptoHasher {
|
||||
}
|
||||
}
|
||||
|
||||
lazy val Sha1: CryptoHasher[Array[Byte], Array[Byte]] = new CryptoHasher[Array[Byte], Array[Byte]] {
|
||||
lazy val Sha1: CryptoHasher.Bytes = new CryptoHasher[Array[Byte], Array[Byte]] {
|
||||
override def hash(msg1: Array[Byte]): Array[Byte] = {
|
||||
val sha1 = new SHA1()
|
||||
sha1.update(msg1.toJSArray)
|
||||
|
24
jvm/src/main/scala/fluence/crypto/hash/CryptoHashers.scala
Normal file
24
jvm/src/main/scala/fluence/crypto/hash/CryptoHashers.scala
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Fluence Labs Limited
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package fluence.crypto.hash
|
||||
|
||||
object CryptoHashers {
|
||||
lazy val Sha1: CryptoHasher.Bytes = JdkCryptoHasher.Sha1
|
||||
|
||||
lazy val Sha256: CryptoHasher.Bytes = JdkCryptoHasher.Sha256
|
||||
}
|
@ -39,9 +39,9 @@ class JdkCryptoHasher(algorithm: String) extends CryptoHasher[Array[Byte], Array
|
||||
|
||||
object JdkCryptoHasher {
|
||||
|
||||
lazy val Sha256 = apply("SHA-256")
|
||||
lazy val Sha1 = apply("SHA-1")
|
||||
lazy val Sha256: CryptoHasher[Array[Byte], Array[Byte]] = apply("SHA-256")
|
||||
lazy val Sha1: CryptoHasher[Array[Byte], Array[Byte]] = apply("SHA-1")
|
||||
|
||||
def apply(algorithm: String): JdkCryptoHasher = new JdkCryptoHasher(algorithm)
|
||||
def apply(algorithm: String): CryptoHasher[Array[Byte], Array[Byte]] = new JdkCryptoHasher(algorithm)
|
||||
|
||||
}
|
||||
|
@ -30,3 +30,7 @@ trait CryptoHasher[M, H] {
|
||||
def hash(msg1: M, msgN: M*): H
|
||||
|
||||
}
|
||||
|
||||
object CryptoHasher {
|
||||
type Bytes = CryptoHasher[Array[Byte], Array[Byte]]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user