123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- .class public final Lokio/HashingSink;
- .super Lokio/ForwardingSink;
- .source ""
- # instance fields
- .field private final mac:Ljavax/crypto/Mac;
- .field private final messageDigest:Ljava/security/MessageDigest;
- # direct methods
- .method private constructor <init>(Lokio/Sink;Ljava/lang/String;)V
- .locals 0
- invoke-direct {p0, p1}, Lokio/ForwardingSink;-><init>(Lokio/Sink;)V
- :try_start_0
- invoke-static {p2}, Ljava/security/MessageDigest;->getInstance(Ljava/lang/String;)Ljava/security/MessageDigest;
- move-result-object p1
- iput-object p1, p0, Lokio/HashingSink;->messageDigest:Ljava/security/MessageDigest;
- const/4 p1, 0x0
- iput-object p1, p0, Lokio/HashingSink;->mac:Ljavax/crypto/Mac;
- :try_end_0
- .catch Ljava/security/NoSuchAlgorithmException; {:try_start_0 .. :try_end_0} :catch_0
- return-void
- :catch_0
- new-instance p1, Ljava/lang/AssertionError;
- invoke-direct {p1}, Ljava/lang/AssertionError;-><init>()V
- throw p1
- .end method
- .method private constructor <init>(Lokio/Sink;Lokio/ByteString;Ljava/lang/String;)V
- .locals 1
- invoke-direct {p0, p1}, Lokio/ForwardingSink;-><init>(Lokio/Sink;)V
- :try_start_0
- invoke-static {p3}, Ljavax/crypto/Mac;->getInstance(Ljava/lang/String;)Ljavax/crypto/Mac;
- move-result-object p1
- iput-object p1, p0, Lokio/HashingSink;->mac:Ljavax/crypto/Mac;
- iget-object p1, p0, Lokio/HashingSink;->mac:Ljavax/crypto/Mac;
- new-instance v0, Ljavax/crypto/spec/SecretKeySpec;
- invoke-virtual {p2}, Lokio/ByteString;->toByteArray()[B
- move-result-object p2
- invoke-direct {v0, p2, p3}, Ljavax/crypto/spec/SecretKeySpec;-><init>([BLjava/lang/String;)V
- invoke-virtual {p1, v0}, Ljavax/crypto/Mac;->init(Ljava/security/Key;)V
- const/4 p1, 0x0
- iput-object p1, p0, Lokio/HashingSink;->messageDigest:Ljava/security/MessageDigest;
- :try_end_0
- .catch Ljava/security/NoSuchAlgorithmException; {:try_start_0 .. :try_end_0} :catch_1
- .catch Ljava/security/InvalidKeyException; {:try_start_0 .. :try_end_0} :catch_0
- return-void
- :catch_0
- move-exception p1
- new-instance p2, Ljava/lang/IllegalArgumentException;
- invoke-direct {p2, p1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/Throwable;)V
- throw p2
- :catch_1
- new-instance p1, Ljava/lang/AssertionError;
- invoke-direct {p1}, Ljava/lang/AssertionError;-><init>()V
- throw p1
- .end method
- .method public static hmacSha1(Lokio/Sink;Lokio/ByteString;)Lokio/HashingSink;
- .locals 2
- new-instance v0, Lokio/HashingSink;
- const-string v1, "HmacSHA1"
- invoke-direct {v0, p0, p1, v1}, Lokio/HashingSink;-><init>(Lokio/Sink;Lokio/ByteString;Ljava/lang/String;)V
- return-object v0
- .end method
- .method public static hmacSha256(Lokio/Sink;Lokio/ByteString;)Lokio/HashingSink;
- .locals 2
- new-instance v0, Lokio/HashingSink;
- const-string v1, "HmacSHA256"
- invoke-direct {v0, p0, p1, v1}, Lokio/HashingSink;-><init>(Lokio/Sink;Lokio/ByteString;Ljava/lang/String;)V
- return-object v0
- .end method
- .method public static hmacSha512(Lokio/Sink;Lokio/ByteString;)Lokio/HashingSink;
- .locals 2
- new-instance v0, Lokio/HashingSink;
- const-string v1, "HmacSHA512"
- invoke-direct {v0, p0, p1, v1}, Lokio/HashingSink;-><init>(Lokio/Sink;Lokio/ByteString;Ljava/lang/String;)V
- return-object v0
- .end method
- .method public static md5(Lokio/Sink;)Lokio/HashingSink;
- .locals 2
- new-instance v0, Lokio/HashingSink;
- const-string v1, "MD5"
- invoke-direct {v0, p0, v1}, Lokio/HashingSink;-><init>(Lokio/Sink;Ljava/lang/String;)V
- return-object v0
- .end method
- .method public static sha1(Lokio/Sink;)Lokio/HashingSink;
- .locals 2
- new-instance v0, Lokio/HashingSink;
- const-string v1, "SHA-1"
- invoke-direct {v0, p0, v1}, Lokio/HashingSink;-><init>(Lokio/Sink;Ljava/lang/String;)V
- return-object v0
- .end method
- .method public static sha256(Lokio/Sink;)Lokio/HashingSink;
- .locals 2
- new-instance v0, Lokio/HashingSink;
- const-string v1, "SHA-256"
- invoke-direct {v0, p0, v1}, Lokio/HashingSink;-><init>(Lokio/Sink;Ljava/lang/String;)V
- return-object v0
- .end method
- .method public static sha512(Lokio/Sink;)Lokio/HashingSink;
- .locals 2
- new-instance v0, Lokio/HashingSink;
- const-string v1, "SHA-512"
- invoke-direct {v0, p0, v1}, Lokio/HashingSink;-><init>(Lokio/Sink;Ljava/lang/String;)V
- return-object v0
- .end method
- # virtual methods
- .method public hash()Lokio/ByteString;
- .locals 1
- iget-object v0, p0, Lokio/HashingSink;->messageDigest:Ljava/security/MessageDigest;
- if-eqz v0, :cond_0
- invoke-virtual {v0}, Ljava/security/MessageDigest;->digest()[B
- move-result-object v0
- goto :goto_0
- :cond_0
- iget-object v0, p0, Lokio/HashingSink;->mac:Ljavax/crypto/Mac;
- invoke-virtual {v0}, Ljavax/crypto/Mac;->doFinal()[B
- move-result-object v0
- :goto_0
- invoke-static {v0}, Lokio/ByteString;->of([B)Lokio/ByteString;
- move-result-object v0
- return-object v0
- .end method
- .method public write(Lokio/Buffer;J)V
- .locals 7
- .annotation system Ldalvik/annotation/Throws;
- value = {
- Ljava/io/IOException;
- }
- .end annotation
- iget-wide v0, p1, Lokio/Buffer;->size:J
- const-wide/16 v2, 0x0
- move-wide v4, p2
- invoke-static/range {v0 .. v5}, Lokio/Util;->checkOffsetAndCount(JJJ)V
- iget-object v0, p1, Lokio/Buffer;->head:Lokio/Segment;
- const-wide/16 v1, 0x0
- :goto_0
- cmp-long v3, v1, p2
- if-gez v3, :cond_1
- sub-long v3, p2, v1
- iget v5, v0, Lokio/Segment;->limit:I
- iget v6, v0, Lokio/Segment;->pos:I
- sub-int/2addr v5, v6
- int-to-long v5, v5
- invoke-static {v3, v4, v5, v6}, Ljava/lang/Math;->min(JJ)J
- move-result-wide v3
- long-to-int v4, v3
- iget-object v3, p0, Lokio/HashingSink;->messageDigest:Ljava/security/MessageDigest;
- if-eqz v3, :cond_0
- iget-object v5, v0, Lokio/Segment;->data:[B
- iget v6, v0, Lokio/Segment;->pos:I
- invoke-virtual {v3, v5, v6, v4}, Ljava/security/MessageDigest;->update([BII)V
- goto :goto_1
- :cond_0
- iget-object v3, p0, Lokio/HashingSink;->mac:Ljavax/crypto/Mac;
- iget-object v5, v0, Lokio/Segment;->data:[B
- iget v6, v0, Lokio/Segment;->pos:I
- invoke-virtual {v3, v5, v6, v4}, Ljavax/crypto/Mac;->update([BII)V
- :goto_1
- int-to-long v3, v4
- add-long/2addr v1, v3
- iget-object v0, v0, Lokio/Segment;->next:Lokio/Segment;
- goto :goto_0
- :cond_1
- invoke-super {p0, p1, p2, p3}, Lokio/ForwardingSink;->write(Lokio/Buffer;J)V
- return-void
- .end method
|