HashingSource.smali 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. .class public final Lokio/HashingSource;
  2. .super Lokio/ForwardingSource;
  3. .source ""
  4. # instance fields
  5. .field private final mac:Ljavax/crypto/Mac;
  6. .field private final messageDigest:Ljava/security/MessageDigest;
  7. # direct methods
  8. .method private constructor <init>(Lokio/Source;Ljava/lang/String;)V
  9. .locals 0
  10. invoke-direct {p0, p1}, Lokio/ForwardingSource;-><init>(Lokio/Source;)V
  11. :try_start_0
  12. invoke-static {p2}, Ljava/security/MessageDigest;->getInstance(Ljava/lang/String;)Ljava/security/MessageDigest;
  13. move-result-object p1
  14. iput-object p1, p0, Lokio/HashingSource;->messageDigest:Ljava/security/MessageDigest;
  15. const/4 p1, 0x0
  16. iput-object p1, p0, Lokio/HashingSource;->mac:Ljavax/crypto/Mac;
  17. :try_end_0
  18. .catch Ljava/security/NoSuchAlgorithmException; {:try_start_0 .. :try_end_0} :catch_0
  19. return-void
  20. :catch_0
  21. new-instance p1, Ljava/lang/AssertionError;
  22. invoke-direct {p1}, Ljava/lang/AssertionError;-><init>()V
  23. throw p1
  24. .end method
  25. .method private constructor <init>(Lokio/Source;Lokio/ByteString;Ljava/lang/String;)V
  26. .locals 1
  27. invoke-direct {p0, p1}, Lokio/ForwardingSource;-><init>(Lokio/Source;)V
  28. :try_start_0
  29. invoke-static {p3}, Ljavax/crypto/Mac;->getInstance(Ljava/lang/String;)Ljavax/crypto/Mac;
  30. move-result-object p1
  31. iput-object p1, p0, Lokio/HashingSource;->mac:Ljavax/crypto/Mac;
  32. iget-object p1, p0, Lokio/HashingSource;->mac:Ljavax/crypto/Mac;
  33. new-instance v0, Ljavax/crypto/spec/SecretKeySpec;
  34. invoke-virtual {p2}, Lokio/ByteString;->toByteArray()[B
  35. move-result-object p2
  36. invoke-direct {v0, p2, p3}, Ljavax/crypto/spec/SecretKeySpec;-><init>([BLjava/lang/String;)V
  37. invoke-virtual {p1, v0}, Ljavax/crypto/Mac;->init(Ljava/security/Key;)V
  38. const/4 p1, 0x0
  39. iput-object p1, p0, Lokio/HashingSource;->messageDigest:Ljava/security/MessageDigest;
  40. :try_end_0
  41. .catch Ljava/security/NoSuchAlgorithmException; {:try_start_0 .. :try_end_0} :catch_1
  42. .catch Ljava/security/InvalidKeyException; {:try_start_0 .. :try_end_0} :catch_0
  43. return-void
  44. :catch_0
  45. move-exception p1
  46. new-instance p2, Ljava/lang/IllegalArgumentException;
  47. invoke-direct {p2, p1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/Throwable;)V
  48. throw p2
  49. :catch_1
  50. new-instance p1, Ljava/lang/AssertionError;
  51. invoke-direct {p1}, Ljava/lang/AssertionError;-><init>()V
  52. throw p1
  53. .end method
  54. .method public static hmacSha1(Lokio/Source;Lokio/ByteString;)Lokio/HashingSource;
  55. .locals 2
  56. new-instance v0, Lokio/HashingSource;
  57. const-string v1, "HmacSHA1"
  58. invoke-direct {v0, p0, p1, v1}, Lokio/HashingSource;-><init>(Lokio/Source;Lokio/ByteString;Ljava/lang/String;)V
  59. return-object v0
  60. .end method
  61. .method public static hmacSha256(Lokio/Source;Lokio/ByteString;)Lokio/HashingSource;
  62. .locals 2
  63. new-instance v0, Lokio/HashingSource;
  64. const-string v1, "HmacSHA256"
  65. invoke-direct {v0, p0, p1, v1}, Lokio/HashingSource;-><init>(Lokio/Source;Lokio/ByteString;Ljava/lang/String;)V
  66. return-object v0
  67. .end method
  68. .method public static md5(Lokio/Source;)Lokio/HashingSource;
  69. .locals 2
  70. new-instance v0, Lokio/HashingSource;
  71. const-string v1, "MD5"
  72. invoke-direct {v0, p0, v1}, Lokio/HashingSource;-><init>(Lokio/Source;Ljava/lang/String;)V
  73. return-object v0
  74. .end method
  75. .method public static sha1(Lokio/Source;)Lokio/HashingSource;
  76. .locals 2
  77. new-instance v0, Lokio/HashingSource;
  78. const-string v1, "SHA-1"
  79. invoke-direct {v0, p0, v1}, Lokio/HashingSource;-><init>(Lokio/Source;Ljava/lang/String;)V
  80. return-object v0
  81. .end method
  82. .method public static sha256(Lokio/Source;)Lokio/HashingSource;
  83. .locals 2
  84. new-instance v0, Lokio/HashingSource;
  85. const-string v1, "SHA-256"
  86. invoke-direct {v0, p0, v1}, Lokio/HashingSource;-><init>(Lokio/Source;Ljava/lang/String;)V
  87. return-object v0
  88. .end method
  89. # virtual methods
  90. .method public hash()Lokio/ByteString;
  91. .locals 1
  92. iget-object v0, p0, Lokio/HashingSource;->messageDigest:Ljava/security/MessageDigest;
  93. if-eqz v0, :cond_0
  94. invoke-virtual {v0}, Ljava/security/MessageDigest;->digest()[B
  95. move-result-object v0
  96. goto :goto_0
  97. :cond_0
  98. iget-object v0, p0, Lokio/HashingSource;->mac:Ljavax/crypto/Mac;
  99. invoke-virtual {v0}, Ljavax/crypto/Mac;->doFinal()[B
  100. move-result-object v0
  101. :goto_0
  102. invoke-static {v0}, Lokio/ByteString;->of([B)Lokio/ByteString;
  103. move-result-object v0
  104. return-object v0
  105. .end method
  106. .method public read(Lokio/Buffer;J)J
  107. .locals 8
  108. .annotation system Ldalvik/annotation/Throws;
  109. value = {
  110. Ljava/io/IOException;
  111. }
  112. .end annotation
  113. invoke-super {p0, p1, p2, p3}, Lokio/ForwardingSource;->read(Lokio/Buffer;J)J
  114. move-result-wide p2
  115. const-wide/16 v0, -0x1
  116. cmp-long v2, p2, v0
  117. if-eqz v2, :cond_2
  118. iget-wide v0, p1, Lokio/Buffer;->size:J
  119. sub-long v2, v0, p2
  120. iget-object v4, p1, Lokio/Buffer;->head:Lokio/Segment;
  121. :goto_0
  122. cmp-long v5, v0, v2
  123. if-lez v5, :cond_0
  124. iget-object v4, v4, Lokio/Segment;->prev:Lokio/Segment;
  125. iget v5, v4, Lokio/Segment;->limit:I
  126. iget v6, v4, Lokio/Segment;->pos:I
  127. sub-int/2addr v5, v6
  128. int-to-long v5, v5
  129. sub-long/2addr v0, v5
  130. goto :goto_0
  131. :cond_0
  132. :goto_1
  133. iget-wide v5, p1, Lokio/Buffer;->size:J
  134. cmp-long v7, v0, v5
  135. if-gez v7, :cond_2
  136. iget v5, v4, Lokio/Segment;->pos:I
  137. int-to-long v5, v5
  138. add-long/2addr v5, v2
  139. sub-long/2addr v5, v0
  140. long-to-int v2, v5
  141. iget-object v3, p0, Lokio/HashingSource;->messageDigest:Ljava/security/MessageDigest;
  142. if-eqz v3, :cond_1
  143. iget-object v5, v4, Lokio/Segment;->data:[B
  144. iget v6, v4, Lokio/Segment;->limit:I
  145. sub-int/2addr v6, v2
  146. invoke-virtual {v3, v5, v2, v6}, Ljava/security/MessageDigest;->update([BII)V
  147. goto :goto_2
  148. :cond_1
  149. iget-object v3, p0, Lokio/HashingSource;->mac:Ljavax/crypto/Mac;
  150. iget-object v5, v4, Lokio/Segment;->data:[B
  151. iget v6, v4, Lokio/Segment;->limit:I
  152. sub-int/2addr v6, v2
  153. invoke-virtual {v3, v5, v2, v6}, Ljavax/crypto/Mac;->update([BII)V
  154. :goto_2
  155. iget v2, v4, Lokio/Segment;->limit:I
  156. iget v3, v4, Lokio/Segment;->pos:I
  157. sub-int/2addr v2, v3
  158. int-to-long v2, v2
  159. add-long/2addr v2, v0
  160. iget-object v4, v4, Lokio/Segment;->next:Lokio/Segment;
  161. move-wide v0, v2
  162. goto :goto_1
  163. :cond_2
  164. return-wide p2
  165. .end method