digesting strings according to SHA-1 -- Scala version;
authorwenzelm
Tue Aug 17 23:23:29 2010 +0200 (2010-08-17)
changeset 38473bd96f2a5beb0
parent 38472 3c5716b2e7b6
child 38474 e498dc2eb576
digesting strings according to SHA-1 -- Scala version;
src/Pure/General/sha1.scala
src/Pure/build-jars
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Pure/General/sha1.scala	Tue Aug 17 23:23:29 2010 +0200
     1.3 @@ -0,0 +1,28 @@
     1.4 +/*  Title:      Pure/General/sha1.scala
     1.5 +    Author:     Makarius
     1.6 +
     1.7 +Digesting strings according to SHA-1 (see RFC 3174).
     1.8 +*/
     1.9 +
    1.10 +package isabelle
    1.11 +
    1.12 +
    1.13 +import java.security.MessageDigest
    1.14 +
    1.15 +
    1.16 +object SHA1
    1.17 +{
    1.18 +  def digest_bytes(bytes: Array[Byte]): String =
    1.19 +  {
    1.20 +    val result = new StringBuilder
    1.21 +    for (b <- MessageDigest.getInstance("SHA").digest(bytes)) {
    1.22 +      val i = b.asInstanceOf[Int] & 0xFF
    1.23 +      if (i < 16) result += '0'
    1.24 +      result ++= Integer.toHexString(i)
    1.25 +    }
    1.26 +    result.toString
    1.27 +  }
    1.28 +
    1.29 +  def digest(s: String): String = digest_bytes(Standard_System.string_bytes(s))
    1.30 +}
    1.31 +
     2.1 --- a/src/Pure/build-jars	Tue Aug 17 23:00:51 2010 +0200
     2.2 +++ b/src/Pure/build-jars	Tue Aug 17 23:23:29 2010 +0200
     2.3 @@ -29,6 +29,7 @@
     2.4    General/position.scala
     2.5    General/pretty.scala
     2.6    General/scan.scala
     2.7 +  General/sha1.scala
     2.8    General/symbol.scala
     2.9    General/xml.scala
    2.10    General/xml_data.scala