From 08ac1c09815fada8b59a584393945f07c6e6e3c6 Mon Sep 17 00:00:00 2001 From: vmikheev Date: Wed, 27 Jun 2018 00:27:05 +0300 Subject: [PATCH 1/6] Use ScorexLogging from the Scorex-util repository --- build.sbt | 3 ++- lock.sbt | 3 ++- .../scorex/crypto/authds/TwoPartyProofElement.scala | 2 +- .../crypto/authds/avltree/batch/BatchAVLProver.scala | 3 ++- .../crypto/authds/avltree/batch/Operation.scala | 2 +- .../crypto/authds/avltree/batch/ToStringHelper.scala | 4 ++-- .../scorex/crypto/authds/merkle/MerkleProof.scala | 2 +- .../scorex/crypto/authds/merkle/MerkleTree.scala | 3 +-- .../scala/scorex/crypto/signatures/Curve25519.scala | 7 +++---- src/main/scala/scorex/utils/ScryptoLogging.scala | 12 ------------ 10 files changed, 15 insertions(+), 26 deletions(-) delete mode 100644 src/main/scala/scorex/utils/ScryptoLogging.scala diff --git a/build.sbt b/build.sbt index f5e0dff4..ea03e405 100644 --- a/build.sbt +++ b/build.sbt @@ -28,7 +28,8 @@ libraryDependencies ++= Seq( "com.typesafe.scala-logging" %% "scala-logging" % "3.+", "ch.qos.logback" % "logback-classic" % "1.+", "org.whispersystems" % "curve25519-java" % "+", - "org.bouncycastle" % "bcprov-jdk15on" % "1.+" + "org.bouncycastle" % "bcprov-jdk15on" % "1.+", + "org.scorexfoundation" %% "scorex-util" % "1.0.0" ) libraryDependencies ++= Seq( diff --git a/lock.sbt b/lock.sbt index 80815a40..eec22c9b 100644 --- a/lock.sbt +++ b/lock.sbt @@ -10,7 +10,8 @@ dependencyOverrides in ThisBuild ++= Seq( "javax.activation" % "activation" % "1.1", "org.bouncycastle" % "bcprov-jdk15on" % "1.59", "org.rudogma" % "supertagged_2.12" % "1.4", + "org.scorexfoundation" % "scorex-util_2.12" % "1.0.0", "org.slf4j" % "slf4j-api" % "1.8.0-beta1", "org.whispersystems" % "curve25519-java" % "0.5.0" ) -// LIBRARY_DEPENDENCIES_HASH 6da534ddce5e26a47dc87a4777336311fe979572 +// LIBRARY_DEPENDENCIES_HASH d13352f4a3525b5bf9bf982114454d03cccdb705 diff --git a/src/main/scala/scorex/crypto/authds/TwoPartyProofElement.scala b/src/main/scala/scorex/crypto/authds/TwoPartyProofElement.scala index 465b82a1..13ce3f35 100644 --- a/src/main/scala/scorex/crypto/authds/TwoPartyProofElement.scala +++ b/src/main/scala/scorex/crypto/authds/TwoPartyProofElement.scala @@ -1,7 +1,7 @@ package scorex.crypto.authds import scorex.crypto.authds.legacy.treap.Level -import scorex.utils.{ScorexEncoding, ScryptoLogging} +import scorex.utils.ScorexEncoding trait TwoPartyProofElement extends ScorexEncoding { val bytes: Array[Byte] diff --git a/src/main/scala/scorex/crypto/authds/avltree/batch/BatchAVLProver.scala b/src/main/scala/scorex/crypto/authds/avltree/batch/BatchAVLProver.scala index 70373722..48170282 100644 --- a/src/main/scala/scorex/crypto/authds/avltree/batch/BatchAVLProver.scala +++ b/src/main/scala/scorex/crypto/authds/avltree/batch/BatchAVLProver.scala @@ -3,6 +3,7 @@ package scorex.crypto.authds.avltree.batch import com.google.common.primitives.Ints import scorex.crypto.authds._ import scorex.crypto.hash.{Blake2b256, CryptographicHash, Digest} +import scorex.util.ScorexLogging import scorex.utils.ByteArray import scala.annotation.tailrec @@ -27,7 +28,7 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int oldRootAndHeight: Option[(ProverNodes[D], Int)] = None, val collectChangedNodes: Boolean = true) (implicit val hf: HF = Blake2b256) - extends AuthenticatedTreeOps[D] with ToStringHelper { + extends AuthenticatedTreeOps[D] with ToStringHelper with ScorexLogging { protected val labelLength = hf.DigestSize diff --git a/src/main/scala/scorex/crypto/authds/avltree/batch/Operation.scala b/src/main/scala/scorex/crypto/authds/avltree/batch/Operation.scala index 84a5c10f..7e5f178f 100644 --- a/src/main/scala/scorex/crypto/authds/avltree/batch/Operation.scala +++ b/src/main/scala/scorex/crypto/authds/avltree/batch/Operation.scala @@ -2,7 +2,7 @@ package scorex.crypto.authds.avltree.batch import com.google.common.primitives.Longs import scorex.crypto.authds.{ADKey, ADValue} -import scorex.utils.{ScorexEncoding, ScryptoLogging} +import scorex.utils.ScorexEncoding import scala.util.{Failure, Success, Try} diff --git a/src/main/scala/scorex/crypto/authds/avltree/batch/ToStringHelper.scala b/src/main/scala/scorex/crypto/authds/avltree/batch/ToStringHelper.scala index 4878f347..703623da 100644 --- a/src/main/scala/scorex/crypto/authds/avltree/batch/ToStringHelper.scala +++ b/src/main/scala/scorex/crypto/authds/avltree/batch/ToStringHelper.scala @@ -1,8 +1,8 @@ package scorex.crypto.authds.avltree.batch -import scorex.utils.{ScorexEncoding, ScryptoLogging} +import scorex.utils.ScorexEncoding -trait ToStringHelper extends ScryptoLogging with ScorexEncoding { +trait ToStringHelper extends ScorexEncoding { //Needed for debug (toString) only protected def arrayToString(a: Array[Byte]): String = encoder.encode(a).take(8) } diff --git a/src/main/scala/scorex/crypto/authds/merkle/MerkleProof.scala b/src/main/scala/scorex/crypto/authds/merkle/MerkleProof.scala index ba8c73a3..4b198094 100644 --- a/src/main/scala/scorex/crypto/authds/merkle/MerkleProof.scala +++ b/src/main/scala/scorex/crypto/authds/merkle/MerkleProof.scala @@ -2,7 +2,7 @@ package scorex.crypto.authds.merkle import scorex.crypto.authds.{LeafData, Side} import scorex.crypto.hash.{CryptographicHash, Digest} -import scorex.utils.{ScorexEncoding, ScryptoLogging} +import scorex.utils.ScorexEncoding /** * Proof is given leaf data, leaf hash sibling and also siblings for parent nodes. Using this data, it is possible to diff --git a/src/main/scala/scorex/crypto/authds/merkle/MerkleTree.scala b/src/main/scala/scorex/crypto/authds/merkle/MerkleTree.scala index 85d452cd..d51a5b8b 100644 --- a/src/main/scala/scorex/crypto/authds/merkle/MerkleTree.scala +++ b/src/main/scala/scorex/crypto/authds/merkle/MerkleTree.scala @@ -2,7 +2,6 @@ package scorex.crypto.authds.merkle import scorex.crypto.authds.{LeafData, Side} import scorex.crypto.hash._ -import scorex.utils.ScryptoLogging import scala.annotation.tailrec import scala.collection.mutable @@ -64,7 +63,7 @@ case class MerkleTree[D <: Digest](topNode: Node[D], } } -object MerkleTree extends ScryptoLogging { +object MerkleTree { val LeafPrefix: Byte = 0: Byte val InternalNodePrefix: Byte = 1: Byte diff --git a/src/main/scala/scorex/crypto/signatures/Curve25519.scala b/src/main/scala/scorex/crypto/signatures/Curve25519.scala index 1968ba2a..75718fcc 100644 --- a/src/main/scala/scorex/crypto/signatures/Curve25519.scala +++ b/src/main/scala/scorex/crypto/signatures/Curve25519.scala @@ -2,12 +2,13 @@ package scorex.crypto.signatures import java.lang.reflect.Constructor -import org.slf4j.LoggerFactory import org.whispersystems.curve25519.OpportunisticCurve25519Provider import scorex.crypto.hash.Sha256 +import scorex.util.ScorexLogging + import scala.util.{Failure, Try} -object Curve25519 extends EllipticCurveSignatureScheme { +object Curve25519 extends EllipticCurveSignatureScheme with ScorexLogging { val SignatureLength25519 = 64 val KeyLength25519 = 32 @@ -51,6 +52,4 @@ object Curve25519 extends EllipticCurveSignatureScheme { override def createSharedSecret(privateKey: PrivateKey, publicKey: PublicKey): SharedSecret = { SharedSecret @@ provider.calculateAgreement(privateKey, publicKey) } - - protected lazy val log = LoggerFactory.getLogger(this.getClass) } \ No newline at end of file diff --git a/src/main/scala/scorex/utils/ScryptoLogging.scala b/src/main/scala/scorex/utils/ScryptoLogging.scala deleted file mode 100644 index b6fa9a4a..00000000 --- a/src/main/scala/scorex/utils/ScryptoLogging.scala +++ /dev/null @@ -1,12 +0,0 @@ -package scorex.utils - -import com.typesafe.scalalogging.StrictLogging - -/** - * Trait with logger - * TODO extract to ScorexUtils - */ -trait ScryptoLogging extends StrictLogging { - @inline protected def log = logger - -} \ No newline at end of file From ec9b42710ba48eb7d8161d75c902df6ed637bdcd Mon Sep 17 00:00:00 2001 From: vmikheev Date: Fri, 3 Aug 2018 15:24:30 +0300 Subject: [PATCH 2/6] Update scorex-util version --- build.sbt | 3 ++- lock.sbt | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build.sbt b/build.sbt index ea03e405..41b93932 100644 --- a/build.sbt +++ b/build.sbt @@ -6,6 +6,7 @@ lazy val commonSettings = Seq( organization := "org.scorexfoundation", version := "2.1.2", scalaVersion := "2.12.5", + resolvers += Resolver.sonatypeRepo("public"), licenses := Seq("CC0" -> url("https://creativecommons.org/publicdomain/zero/1.0/legalcode")), homepage := Some(url("https://github.com/input-output-hk/scrypto")), pomExtra := @@ -29,7 +30,7 @@ libraryDependencies ++= Seq( "ch.qos.logback" % "logback-classic" % "1.+", "org.whispersystems" % "curve25519-java" % "+", "org.bouncycastle" % "bcprov-jdk15on" % "1.+", - "org.scorexfoundation" %% "scorex-util" % "1.0.0" + "org.scorexfoundation" %% "scorex-util" % "0.1.1-SNAPSHOT" ) libraryDependencies ++= Seq( diff --git a/lock.sbt b/lock.sbt index eec22c9b..6ea0c8d6 100644 --- a/lock.sbt +++ b/lock.sbt @@ -8,10 +8,10 @@ dependencyOverrides in ThisBuild ++= Seq( "com.sun.mail" % "javax.mail" % "1.6.0", "com.typesafe.scala-logging" % "scala-logging_2.12" % "3.9.0", "javax.activation" % "activation" % "1.1", - "org.bouncycastle" % "bcprov-jdk15on" % "1.59", + "org.bouncycastle" % "bcprov-jdk15on" % "1.60", "org.rudogma" % "supertagged_2.12" % "1.4", - "org.scorexfoundation" % "scorex-util_2.12" % "1.0.0", + "org.scorexfoundation" % "scorex-util_2.12" % "0.1.1-SNAPSHOT", "org.slf4j" % "slf4j-api" % "1.8.0-beta1", "org.whispersystems" % "curve25519-java" % "0.5.0" ) -// LIBRARY_DEPENDENCIES_HASH d13352f4a3525b5bf9bf982114454d03cccdb705 +// LIBRARY_DEPENDENCIES_HASH 566ab37b6dd750a11f55c07c094f47be1499f752 From a69818bfc20e5ca2dccae77d80978224933626b5 Mon Sep 17 00:00:00 2001 From: vmikheev Date: Fri, 3 Aug 2018 15:34:12 +0300 Subject: [PATCH 3/6] Type alias for ScryptoLogging --- src/main/scala/scorex/utils/package.scala | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/scala/scorex/utils/package.scala diff --git a/src/main/scala/scorex/utils/package.scala b/src/main/scala/scorex/utils/package.scala new file mode 100644 index 00000000..b435bdde --- /dev/null +++ b/src/main/scala/scorex/utils/package.scala @@ -0,0 +1,8 @@ +package scorex + +package object utils { + + @deprecated("Use scorex.util.ScorexLogging instead.", "scorex-util 0.1.0") + type ScryptoLogging = scorex.util.ScorexLogging + +} From 966ec9956ecfdaf0f555101fac54e1186c56122e Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Sat, 4 Aug 2018 10:50:44 +0300 Subject: [PATCH 4/6] delete Base* encoders, ScorexEncoding and switch to aliased from scorex-util; --- .../scala/scorex/crypto/encode/Base16.scala | 71 ------------------- .../scala/scorex/crypto/encode/Base58.scala | 66 ----------------- .../scala/scorex/crypto/encode/Base64.scala | 13 ---- .../scorex/crypto/encode/BytesEncoder.scala | 14 ---- .../scala/scorex/crypto/encode/package.scala | 14 ++++ .../scala/scorex/utils/ScorexEncoding.scala | 11 --- src/main/scala/scorex/utils/package.scala | 2 + .../crypto/encode/Base16Specification.scala | 5 -- .../crypto/encode/Base58Specification.scala | 40 ----------- .../crypto/encode/Base64Specification.scala | 5 -- .../crypto/encode/EncoderSpecification.scala | 32 --------- 11 files changed, 16 insertions(+), 257 deletions(-) delete mode 100644 src/main/scala/scorex/crypto/encode/Base16.scala delete mode 100644 src/main/scala/scorex/crypto/encode/Base58.scala delete mode 100644 src/main/scala/scorex/crypto/encode/Base64.scala delete mode 100644 src/main/scala/scorex/crypto/encode/BytesEncoder.scala create mode 100644 src/main/scala/scorex/crypto/encode/package.scala delete mode 100644 src/main/scala/scorex/utils/ScorexEncoding.scala delete mode 100644 src/test/scala/scorex/crypto/encode/Base16Specification.scala delete mode 100644 src/test/scala/scorex/crypto/encode/Base58Specification.scala delete mode 100644 src/test/scala/scorex/crypto/encode/Base64Specification.scala delete mode 100644 src/test/scala/scorex/crypto/encode/EncoderSpecification.scala diff --git a/src/main/scala/scorex/crypto/encode/Base16.scala b/src/main/scala/scorex/crypto/encode/Base16.scala deleted file mode 100644 index cb1e2433..00000000 --- a/src/main/scala/scorex/crypto/encode/Base16.scala +++ /dev/null @@ -1,71 +0,0 @@ -package scorex.crypto.encode - -import java.io.IOException - -import org.bouncycastle.util.encoders.Hex - -import scala.util.{Failure, Success, Try} - -object Base16 extends BytesEncoder { - - override val Alphabet: String = "0123456789abcdefABCDEF" - private val hexArray = "0123456789abcdef".toCharArray - - private val hexIndex: Array[Byte] = { - var index = Array.fill[Byte](128)(0xff.toByte) - hexArray.zipWithIndex.foreach { case (c, i) => - index(c) = i.toByte - } - "abcdef".toCharArray.foreach{ c => - index(c.toUpper) = index(c) - } - index - } - - def encode(input: Array[Byte]): String = { - val buf = new Array[Char](input.length * 2) - var j = 0 - while (j < input.length) { - val v = input(j) & 0xFF - buf(j * 2) = hexArray(v >>> 4) - buf(j * 2 + 1)= hexArray(v & 0x0F) - j += 1 - } - new String(buf) - } - - def decode(input: String): Try[Array[Byte]] = { - var (isError, errorMsg) = if (input.length % 2 == 0) { - (false, "") - } else { - (true, s"invalid length ${input.length} of Hex data") - } - - val out = Array.ofDim[Byte](input.length / 2) - var j = 0 - while (j < input.length && !isError) { - val c1 = input(j) - val c2 = input(j + 1) - if (c1 > 0 && c1 < 127 && c2 > 0 && c2 < 127) { - val b1 = hexIndex(c1) - val b2 = hexIndex(c2) - if ((b1 | b2) < 0) { - isError = true - errorMsg = "invalid characters encountered in Hex data" - } else { - out(j / 2) = ((b1 << 4) | b2).toByte - } - } else { - isError = true - errorMsg = "invalid characters encountered in Hex data" - } - j += 2 - } - - if (!isError) { - Success(out) - } else { - Failure(new IOException(errorMsg)) - } - } -} \ No newline at end of file diff --git a/src/main/scala/scorex/crypto/encode/Base58.scala b/src/main/scala/scorex/crypto/encode/Base58.scala deleted file mode 100644 index d9c23b4a..00000000 --- a/src/main/scala/scorex/crypto/encode/Base58.scala +++ /dev/null @@ -1,66 +0,0 @@ -package scorex.crypto.encode - -import scala.util.Try - -/** - * A custom form of base58 is used to encode Scorex addresses. - */ -object Base58 extends BytesEncoder { - val Alphabet: String = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" - private val DecodeTable = Array( - 0, 1, 2, 3, 4, 5, 6, 7, 8, -1, -1, -1, -1, -1, -1, -1, 9, 10, 11, 12, 13, 14, 15, 16, -1, 17, 18, 19, 20, 21, -1, - 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, -1, -1, -1, -1, -1, -1, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, -1, - 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 - ) - - private val Base = BigInt(58) - - override def encode(input: Array[Byte]): String = { - var bi = BigInt(1, input) - val s = new StringBuilder() - if (bi > 0) { - while (bi >= Base) { - val (newBi, mod) = bi /% Base - s.insert(0, Alphabet.charAt(mod.intValue())) - bi = newBi - } - s.insert(0, Alphabet.charAt(bi.intValue())) - } - // Convert leading zeros too. - input.takeWhile(_ == 0).foldLeft(s) { case (ss, _) => - ss.insert(0, Alphabet.charAt(0)) - }.toString() - } - - override def decode(input: String): Try[Array[Byte]] = Try { - val decoded = decodeToBigInteger(input) - - val bytes: Array[Byte] = if (decoded == BigInt(0)) Array.empty else decoded.toByteArray - // We may have got one more byte than we wanted, if the high bit of the next-to-last byte was not zero. - // This is because BigIntegers are represented with twos-compliment notation, - // thus if the high bit of the last byte happens to be 1 another 8 zero bits will be added to - // ensure the number parses as positive. Detect that case here and chop it off. - val stripSignByte = bytes.length > 1 && bytes.head == 0 && bytes(1) < 0 - val stripSignBytePos = if (stripSignByte) 1 else 0 - // Count the leading zeros, if any. - val leadingZeros = input.takeWhile(_ == Alphabet.charAt(0)).length - - // Now cut/pad correctly. Java 6 has a convenience for this, but Android - // can't use it. - val tmp = new Array[Byte](bytes.length - stripSignBytePos + leadingZeros) - System.arraycopy(bytes, stripSignBytePos, tmp, leadingZeros, tmp.length - leadingZeros) - tmp - } - - private def decodeToBigInteger(input: String): BigInt = - // Work backwards through the string. - input.foldRight((BigInt(0), BigInt(1))) { case (ch, (bi, k)) => - val alphaIndex = toBase58(ch).ensuring(_ != -1, "Wrong char in Base58 string") - (bi + BigInt(alphaIndex) * k, k * Base) - }._1 - - private def toBase58(c: Char): Int = { - val x = c.toInt - if (x < 49) -1 else if (x <= 122) DecodeTable(x - 49) else -1 - } -} \ No newline at end of file diff --git a/src/main/scala/scorex/crypto/encode/Base64.scala b/src/main/scala/scorex/crypto/encode/Base64.scala deleted file mode 100644 index 71f442db..00000000 --- a/src/main/scala/scorex/crypto/encode/Base64.scala +++ /dev/null @@ -1,13 +0,0 @@ -package scorex.crypto.encode - -import scala.util.Try - -object Base64 extends BytesEncoder { - - override val Alphabet: String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" - - override def encode(input: Array[Byte]): String = new String(java.util.Base64.getEncoder.encode(input)) - - override def decode(input: String): Try[Array[Byte]] = Try(java.util.Base64.getDecoder.decode(input)) - -} \ No newline at end of file diff --git a/src/main/scala/scorex/crypto/encode/BytesEncoder.scala b/src/main/scala/scorex/crypto/encode/BytesEncoder.scala deleted file mode 100644 index 2a7a995c..00000000 --- a/src/main/scala/scorex/crypto/encode/BytesEncoder.scala +++ /dev/null @@ -1,14 +0,0 @@ -package scorex.crypto.encode - -import scala.util.Try - -trait BytesEncoder { - // allowed characters - val Alphabet: String - - // encode Array[Byte] to String - def encode(input: Array[Byte]): String - - // decode string to Array[Byte]. Return Failure on incorrect character in input - def decode(input: String): Try[Array[Byte]] -} diff --git a/src/main/scala/scorex/crypto/encode/package.scala b/src/main/scala/scorex/crypto/encode/package.scala new file mode 100644 index 00000000..9577903b --- /dev/null +++ b/src/main/scala/scorex/crypto/encode/package.scala @@ -0,0 +1,14 @@ +package scorex.crypto + +package object encode { + + @deprecated("Use scorex.util.encode.BytesEncoder instead.", "scorex-util 0.1.1") + type BytesEncoder = scorex.util.encode.BytesEncoder + + @deprecated("Use scorex.util.encode.Base16 instead.", "scorex-util 0.1.1") + val Base16 = scorex.util.encode.Base16 + @deprecated("Use scorex.util.encode.Base58 instead.", "scorex-util 0.1.1") + val Base58 = scorex.util.encode.Base58 + @deprecated("Use scorex.util.encode.Base64 instead.", "scorex-util 0.1.1") + val Base64 = scorex.util.encode.Base64 +} diff --git a/src/main/scala/scorex/utils/ScorexEncoding.scala b/src/main/scala/scorex/utils/ScorexEncoding.scala deleted file mode 100644 index e0868d49..00000000 --- a/src/main/scala/scorex/utils/ScorexEncoding.scala +++ /dev/null @@ -1,11 +0,0 @@ -package scorex.utils - -import scorex.crypto.encode.{Base16, BytesEncoder} - -/** - * Trait with bytes to string encoder - * TODO extract to ScorexUtils - */ -trait ScorexEncoding { - implicit val encoder: BytesEncoder = Base16 -} diff --git a/src/main/scala/scorex/utils/package.scala b/src/main/scala/scorex/utils/package.scala index b435bdde..39f18064 100644 --- a/src/main/scala/scorex/utils/package.scala +++ b/src/main/scala/scorex/utils/package.scala @@ -5,4 +5,6 @@ package object utils { @deprecated("Use scorex.util.ScorexLogging instead.", "scorex-util 0.1.0") type ScryptoLogging = scorex.util.ScorexLogging + @deprecated("Use scorex.util.ScorexEncoding instead.", "scorex-util 0.1.1") + type ScorexEncoding = scorex.util.ScorexEncoding } diff --git a/src/test/scala/scorex/crypto/encode/Base16Specification.scala b/src/test/scala/scorex/crypto/encode/Base16Specification.scala deleted file mode 100644 index c51d6041..00000000 --- a/src/test/scala/scorex/crypto/encode/Base16Specification.scala +++ /dev/null @@ -1,5 +0,0 @@ -package scorex.crypto.encode - -class Base16Specification extends EncoderSpecification { - override val encoder: BytesEncoder = Base16 -} diff --git a/src/test/scala/scorex/crypto/encode/Base58Specification.scala b/src/test/scala/scorex/crypto/encode/Base58Specification.scala deleted file mode 100644 index 885692a8..00000000 --- a/src/test/scala/scorex/crypto/encode/Base58Specification.scala +++ /dev/null @@ -1,40 +0,0 @@ -package scorex.crypto.encode - -import java.util - -import org.scalacheck.Arbitrary -import org.scalatest.prop.{GeneratorDrivenPropertyChecks, PropertyChecks} -import org.scalatest.{Matchers, PropSpec} - -class Base58Specification extends EncoderSpecification { - - override val encoder: BytesEncoder = Base58 - - property("Base58 encoding then decoding for genesis signature") { - val data = Array.fill(64)(0: Byte) - val encoded = Base58.encode(data) - encoded shouldBe "1111111111111111111111111111111111111111111111111111111111111111" - val restored = Base58.decode(encoded).get - restored.length shouldBe data.length - restored shouldBe data - } - - property("base58 sample") { - val b58 = "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i" - Base58.encode(Base58.decode(b58).get) shouldBe b58 - } - - property("Base58 round trip") { - forAll(Arbitrary.arbString.arbitrary.filter(_.nonEmpty)) { origStr => - val origBytes = origStr.getBytes("UTF-8") - val decodedBytes = Base58.decode(Base58.encode(origBytes)).get - util.Arrays.equals(origBytes, decodedBytes) - } - } - - property("empty string roundtrip") { - import Array.emptyByteArray - Base58.encode(emptyByteArray) shouldBe "" - Base58.decode("").get shouldBe emptyByteArray - } -} diff --git a/src/test/scala/scorex/crypto/encode/Base64Specification.scala b/src/test/scala/scorex/crypto/encode/Base64Specification.scala deleted file mode 100644 index 84f7c3e4..00000000 --- a/src/test/scala/scorex/crypto/encode/Base64Specification.scala +++ /dev/null @@ -1,5 +0,0 @@ -package scorex.crypto.encode - -class Base64Specification extends EncoderSpecification { - override val encoder: BytesEncoder = Base64 -} diff --git a/src/test/scala/scorex/crypto/encode/EncoderSpecification.scala b/src/test/scala/scorex/crypto/encode/EncoderSpecification.scala deleted file mode 100644 index 876519de..00000000 --- a/src/test/scala/scorex/crypto/encode/EncoderSpecification.scala +++ /dev/null @@ -1,32 +0,0 @@ -package scorex.crypto.encode - -import org.scalatest.{Matchers, PropSpec} -import org.scalatest.prop.{GeneratorDrivenPropertyChecks, PropertyChecks} - -trait EncoderSpecification extends PropSpec - with PropertyChecks - with GeneratorDrivenPropertyChecks - with Matchers { - - val encoder: BytesEncoder - - property("Encoding then decoding preserves data") { - forAll { data: Array[Byte] => - whenever(data.length > 0 && data.head != 0) { - val encoded = encoder.encode(data) - encoded.find(c => !encoder.Alphabet.contains(c)) shouldBe None - val restored = encoder.decode(encoded).get - restored shouldBe data - } - } - } - - property("Decoding should return failure on incorrect characters") { - forAll { str: String => - whenever(str.exists(c => !encoder.Alphabet.contains(c))) { - encoder.decode(str).isFailure shouldBe true - } - } - } - -} \ No newline at end of file From bf286da8fca3bac178d35dcb4a65e9de6a4fa4b3 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Thu, 9 Aug 2018 12:26:57 +0300 Subject: [PATCH 5/6] 2.1.3 --- build.sbt | 2 +- release-notes.md | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 65496e8f..ea5f0b34 100644 --- a/build.sbt +++ b/build.sbt @@ -4,7 +4,7 @@ name := "scrypto" lazy val commonSettings = Seq( organization := "org.scorexfoundation", - version := "2.1.3-SNAPSHOT", + version := "2.1.3", scalaVersion := "2.12.5", resolvers += Resolver.sonatypeRepo("public"), licenses := Seq("CC0" -> url("https://creativecommons.org/publicdomain/zero/1.0/legalcode")), diff --git a/release-notes.md b/release-notes.md index bc08b95c..70b6938c 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,3 +1,9 @@ +**2.1.3** +--------- + +* Always explicit encoding in .getBytes String method +* Base* and logging are moved to scorex-utils + **2.1.2** --------- From f372cc796ca07014bba23ad4c685f30b3a2dac69 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Thu, 9 Aug 2018 13:24:20 +0300 Subject: [PATCH 6/6] randomwalk test fix --- .../scorex/crypto/authds/avltree/batch/BatchAVLProver.scala | 2 +- .../crypto/authds/avltree/batch/AVLBatchSpecification.scala | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/scala/scorex/crypto/authds/avltree/batch/BatchAVLProver.scala b/src/main/scala/scorex/crypto/authds/avltree/batch/BatchAVLProver.scala index 48170282..54ca65bf 100644 --- a/src/main/scala/scorex/crypto/authds/avltree/batch/BatchAVLProver.scala +++ b/src/main/scala/scorex/crypto/authds/avltree/batch/BatchAVLProver.scala @@ -355,7 +355,7 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int /** * * @param rand - source of randomness - * @return Random leaf from the tree, that is not positive or negative infinity + * @return Random leaf from the tree that is not positive or negative infinity */ def randomWalk(rand: Random = new Random): Option[(ADKey, ADValue)] = { def internalNodeFn(r: InternalProverNode[D], dummy: Unit.type) = diff --git a/src/test/scala/scorex/crypto/authds/avltree/batch/AVLBatchSpecification.scala b/src/test/scala/scorex/crypto/authds/avltree/batch/AVLBatchSpecification.scala index d489bcdd..dbf87344 100644 --- a/src/test/scala/scorex/crypto/authds/avltree/batch/AVLBatchSpecification.scala +++ b/src/test/scala/scorex/crypto/authds/avltree/batch/AVLBatchSpecification.scala @@ -172,8 +172,8 @@ class AVLBatchSpecification extends PropSpec with GeneratorDrivenPropertyChecks forAll { seed: Long => val e1 = prover.randomWalk(new scala.util.Random(seed)) val e2 = prover.randomWalk(new scala.util.Random(seed)) - e1.get._1 shouldEqual e2.get._1 - e1.get._2 shouldEqual e2.get._2 + e1.map(_._1) shouldEqual e2.map(_._1) + e1.map(_._2) shouldEqual e2.map(_._2) } }