本文整理汇总了Scala中com.google.common.primitives.Longs类的典型用法代码示例。如果您正苦于以下问题:Scala Longs类的具体用法?Scala Longs怎么用?Scala Longs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Longs类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: AnyoneCanSpendNoncedBox
//设置package包名称以及导入依赖的类
package org.ergoplatform.modifiers.mempool.proposition
import com.google.common.primitives.Longs
import io.circe.Json
import io.circe.syntax._
import org.ergoplatform.settings.Algos
import scorex.core.serialization.{JsonSerializable, Serializer}
import scorex.core.transaction.box.Box
import scorex.crypto.encode.Base58
import scala.util.Try
case class AnyoneCanSpendNoncedBox(override val proposition: AnyoneCanSpendProposition,
nonce: Long,
override val value: Long
) extends Box[AnyoneCanSpendProposition] with JsonSerializable {
override lazy val json: Json = Map(
"id" -> Base58.encode(id).asJson,
"nonce" -> nonce.asJson,
"value" -> value.asJson
).asJson
override val id: Array[Byte] = Algos.hash(Longs.toByteArray(nonce))
override type M = AnyoneCanSpendNoncedBox
override lazy val serializer: Serializer[AnyoneCanSpendNoncedBox] = AnyoneCanSpendNoncedBoxSerializer
}
object AnyoneCanSpendNoncedBox {
def idFromBox(prop: AnyoneCanSpendProposition, nonce: Long): Array[Byte] =
Algos.hash(prop.serializer.toBytes(prop) ++ Longs.toByteArray(nonce))
}
object AnyoneCanSpendNoncedBoxSerializer extends Serializer[AnyoneCanSpendNoncedBox] {
val Length: Int = AnyoneCanSpendPropositionSerializer.Length + 8 + 8
override def toBytes(obj: AnyoneCanSpendNoncedBox): Array[Byte] =
obj.proposition.serializer.toBytes(obj.proposition) ++
Longs.toByteArray(obj.nonce) ++
Longs.toByteArray(obj.value)
override def parseBytes(bytes: Array[Byte]): Try[AnyoneCanSpendNoncedBox] = Try {
val proposition = AnyoneCanSpendPropositionSerializer.parseBytes(bytes.take(1)).get
val nonce = Longs.fromByteArray(bytes.slice(1, 9))
val value = Longs.fromByteArray(bytes.slice(9, 17))
AnyoneCanSpendNoncedBox(proposition, nonce, value)
}
}
开发者ID:ergoplatform,项目名称:ergo,代码行数:51,代码来源:AnyoneCanSpendNoncedBox.scala
示例2: MasterKeyTable
//设置package包名称以及导入依赖的类
package im.actor.server.persist
import java.security.MessageDigest
import com.google.common.primitives.Longs
import com.google.protobuf.ByteString
import im.actor.server.db.ActorPostgresDriver.api._
import im.actor.server.model.MasterKey
import scala.concurrent.ExecutionContext
final class MasterKeyTable(tag: Tag) extends Table[MasterKey](tag, "master_keys") {
def authId = column[Long]("auth_id", O.PrimaryKey)
def body = column[ByteString]("body")
def * = (authId, body) <> ((MasterKey.apply _).tupled, MasterKey.unapply)
}
object MasterKeyRepo {
val masterKeys = TableQuery[MasterKeyTable]
val byIdC = Compiled { id: Rep[Long] ?
masterKeys filter (_.authId === id)
}
def create(body: Array[Byte])(implicit ec: ExecutionContext) = {
val md = MessageDigest.getInstance("SHA-256")
val authId = Longs.fromByteArray(md.digest(body).take(java.lang.Long.BYTES))
val masterKey = MasterKey(authId, ByteString.copyFrom(body))
(masterKeys += masterKey) map (_ ? masterKey)
}
def find(authId: Long) = byIdC(authId).result.headOption
}
开发者ID:wex5,项目名称:dangchat-server,代码行数:36,代码来源:MasterKeyRepo.scala
示例3: PartialProof
//设置package包名称以及导入依赖的类
package scorex.perma.consensus
import com.google.common.primitives.{Ints, Longs}
import io.circe.Json
import io.circe.syntax._
import scorex.crypto.encode.Base58
import scorex.serialization.{BytesParseable, BytesSerializable, JsonSerializable}
import scorex.transaction.proof.Signature25519
import scala.util.Try
case class PartialProof(signature: Signature25519, segmentIndex: Long, segment: PermaAuthData) extends JsonSerializable
with BytesSerializable {
lazy val json: Json = Map(
"signature" -> Base58.encode(signature.signature).asJson,
"segmentIndex" -> segmentIndex.asJson,
"segment" -> segment.json
).asJson
override def bytes: Array[Byte] = {
Longs.toByteArray(segmentIndex) ++ arrayWithSize(signature.signature) ++ segment.bytes
}
}
object PartialProof extends BytesParseable[PartialProof] {
override def parseBytes(bytes: Array[Byte]): Try[PartialProof] = Try {
val i = Longs.fromByteArray(bytes.slice(0, 8))
val sigSize = Ints.fromByteArray(bytes.slice(8, 12))
val sig = Signature25519(bytes.slice(12, 12 + sigSize))
val segment = PermaAuthData.parseBytes(bytes.slice(12 + sigSize, bytes.length)).get
PartialProof(sig, i, segment)
}
}
开发者ID:ScorexFoundation,项目名称:perma,代码行数:34,代码来源:PartialProof.scala
示例4: PasswordHash
//设置package包名称以及导入依赖的类
package helpers
import java.security.MessageDigest
import com.google.common.primitives.Longs
object PasswordHash {
def generate(password: String, salt: Long, stretchCount: Int = 1): Long = {
val md = createSha1Encoder
for (_ <- 1 to stretchCount) {
md.update(Longs.toByteArray(salt));
md.update(password.getBytes("utf-8"))
}
Longs.fromByteArray(md.digest())
}
def createSha1Encoder = MessageDigest.getInstance("SHA-1")
}
开发者ID:ruimo,项目名称:store2,代码行数:18,代码来源:PasswordHash.scala
示例5: PasswordHash
//设置package包名称以及导入依赖的类
package helpers
import java.security.SecureRandom
import scala.util.Random
import javax.inject._
import java.security.MessageDigest
import com.google.common.primitives.Longs
@Singleton
class PasswordHash {
val saltSource: SecureRandom = new SecureRandom
def createToken(): Long = saltSource.nextLong
// (salt, password_hash)
def generateWithSalt(password: String, stretchCount: Int = 1000): (Long, Long) = {
val salt = createToken()
(salt, generate(password, salt, stretchCount))
}
def generate(password: String, salt: Long, stretchCount: Int = 1000): Long = {
val md = createSha1Encoder
val saltBytes = Longs.toByteArray(salt)
val passwordBytes = password.getBytes("utf-8")
for (_ <- 1 to stretchCount) {
md.update(saltBytes);
md.update(passwordBytes)
}
Longs.fromByteArray(md.digest())
}
def createSha1Encoder = MessageDigest.getInstance("SHA-256")
def password(length: Int = 24): String =
new Random(saltSource).alphanumeric.take(length).foldLeft(new StringBuilder)(_.append(_)).toString
}
开发者ID:ruimo,项目名称:crud-sample,代码行数:37,代码来源:PasswordHash.scala
注:本文中的com.google.common.primitives.Longs类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论