Kad proto cross (#73)

* Kademlia-protocol cross build

* test:compile error fixed

* CryptoHashers
This commit is contained in:
Dmitry Kurinskiy 2018-03-06 07:15:57 +01:00 committed by GitHub
parent d091146dd2
commit 01eb2abec9
5 changed files with 57 additions and 5 deletions

View 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
}

View File

@ -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)

View 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
}

View File

@ -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)
}

View File

@ -30,3 +30,7 @@ trait CryptoHasher[M, H] {
def hash(msg1: M, msgN: M*): H
}
object CryptoHasher {
type Bytes = CryptoHasher[Array[Byte], Array[Byte]]
}