All Downloads are FREE. Search and download functionalities are using the official Maven repository.

im.actor.acl.ACLBase.scala Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package im.actor.acl

import java.nio.ByteBuffer
import java.security.MessageDigest

import akka.actor.ActorSystem
import im.actor.util.ThreadLocalSecureRandom

trait ACLBase {

  def getMDInstance() = MessageDigest.getInstance("MD5")

  def secretKey()(implicit s: ActorSystem) =
    s.settings.config.getString("secret")

  def hash(s: String, md: MessageDigest = getMDInstance()): Long =
    ByteBuffer.wrap(md.digest(s.getBytes)).getLong

  def randomLong(): Long = randomLong(ThreadLocalSecureRandom.current())

  def randomLong(rng: ThreadLocalSecureRandom): Long = rng.nextLong()

  def randomString(): String = randomString(ThreadLocalSecureRandom.current())

  def randomString(rng: ThreadLocalSecureRandom): String = rng.nextLong().toString

  def nextAccessSalt(rng: ThreadLocalSecureRandom): String = randomString(rng)

  def nextAccessSalt(): String = {
    nextAccessSalt(ThreadLocalSecureRandom.current())
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy