123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- .class public final Lokio/HashingSource;
- .super Lokio/ForwardingSource;
- .source ""
- # instance fields
- .field private final mac:Ljavax/crypto/Mac;
- .field private final messageDigest:Ljava/security/MessageDigest;
- # direct methods
- .method private constructor <init>(Lokio/Source;Ljava/lang/String;)V
- .locals 0
- invoke-direct {p0, p1}, Lokio/ForwardingSource;-><init>(Lokio/Source;)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/HashingSource;->messageDigest:Ljava/security/MessageDigest;
- const/4 p1, 0x0
- iput-object p1, p0, Lokio/HashingSource;->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/Source;Lokio/ByteString;Ljava/lang/String;)V
- .locals 1
- invoke-direct {p0, p1}, Lokio/ForwardingSource;-><init>(Lokio/Source;)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/HashingSource;->mac:Ljavax/crypto/Mac;
- iget-object p1, p0, Lokio/HashingSource;->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/HashingSource;->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/Source;Lokio/ByteString;)Lokio/HashingSource;
- .locals 2
- new-instance v0, Lokio/HashingSource;
- const-string v1, "HmacSHA1"
- invoke-direct {v0, p0, p1, v1}, Lokio/HashingSource;-><init>(Lokio/Source;Lokio/ByteString;Ljava/lang/String;)V
- return-object v0
- .end method
- .method public static hmacSha256(Lokio/Source;Lokio/ByteString;)Lokio/HashingSource;
- .locals 2
- new-instance v0, Lokio/HashingSource;
- const-string v1, "HmacSHA256"
- invoke-direct {v0, p0, p1, v1}, Lokio/HashingSource;-><init>(Lokio/Source;Lokio/ByteString;Ljava/lang/String;)V
- return-object v0
- .end method
- .method public static md5(Lokio/Source;)Lokio/HashingSource;
- .locals 2
- new-instance v0, Lokio/HashingSource;
- const-string v1, "MD5"
- invoke-direct {v0, p0, v1}, Lokio/HashingSource;-><init>(Lokio/Source;Ljava/lang/String;)V
- return-object v0
- .end method
- .method public static sha1(Lokio/Source;)Lokio/HashingSource;
- .locals 2
- new-instance v0, Lokio/HashingSource;
- const-string v1, "SHA-1"
- invoke-direct {v0, p0, v1}, Lokio/HashingSource;-><init>(Lokio/Source;Ljava/lang/String;)V
- return-object v0
- .end method
- .method public static sha256(Lokio/Source;)Lokio/HashingSource;
- .locals 2
- new-instance v0, Lokio/HashingSource;
- const-string v1, "SHA-256"
- invoke-direct {v0, p0, v1}, Lokio/HashingSource;-><init>(Lokio/Source;Ljava/lang/String;)V
- return-object v0
- .end method
- # virtual methods
- .method public hash()Lokio/ByteString;
- .locals 1
- iget-object v0, p0, Lokio/HashingSource;->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/HashingSource;->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 read(Lokio/Buffer;J)J
- .locals 8
- .annotation system Ldalvik/annotation/Throws;
- value = {
- Ljava/io/IOException;
- }
- .end annotation
- invoke-super {p0, p1, p2, p3}, Lokio/ForwardingSource;->read(Lokio/Buffer;J)J
- move-result-wide p2
- const-wide/16 v0, -0x1
- cmp-long v2, p2, v0
- if-eqz v2, :cond_2
- iget-wide v0, p1, Lokio/Buffer;->size:J
- sub-long v2, v0, p2
- iget-object v4, p1, Lokio/Buffer;->head:Lokio/Segment;
- :goto_0
- cmp-long v5, v0, v2
- if-lez v5, :cond_0
- iget-object v4, v4, Lokio/Segment;->prev:Lokio/Segment;
- iget v5, v4, Lokio/Segment;->limit:I
- iget v6, v4, Lokio/Segment;->pos:I
- sub-int/2addr v5, v6
- int-to-long v5, v5
- sub-long/2addr v0, v5
- goto :goto_0
- :cond_0
- :goto_1
- iget-wide v5, p1, Lokio/Buffer;->size:J
- cmp-long v7, v0, v5
- if-gez v7, :cond_2
- iget v5, v4, Lokio/Segment;->pos:I
- int-to-long v5, v5
- add-long/2addr v5, v2
- sub-long/2addr v5, v0
- long-to-int v2, v5
- iget-object v3, p0, Lokio/HashingSource;->messageDigest:Ljava/security/MessageDigest;
- if-eqz v3, :cond_1
- iget-object v5, v4, Lokio/Segment;->data:[B
- iget v6, v4, Lokio/Segment;->limit:I
- sub-int/2addr v6, v2
- invoke-virtual {v3, v5, v2, v6}, Ljava/security/MessageDigest;->update([BII)V
- goto :goto_2
- :cond_1
- iget-object v3, p0, Lokio/HashingSource;->mac:Ljavax/crypto/Mac;
- iget-object v5, v4, Lokio/Segment;->data:[B
- iget v6, v4, Lokio/Segment;->limit:I
- sub-int/2addr v6, v2
- invoke-virtual {v3, v5, v2, v6}, Ljavax/crypto/Mac;->update([BII)V
- :goto_2
- iget v2, v4, Lokio/Segment;->limit:I
- iget v3, v4, Lokio/Segment;->pos:I
- sub-int/2addr v2, v3
- int-to-long v2, v2
- add-long/2addr v2, v0
- iget-object v4, v4, Lokio/Segment;->next:Lokio/Segment;
- move-wide v0, v2
- goto :goto_1
- :cond_2
- return-wide p2
- .end method
|