StreamUtil.smali

.class Lorg/spongycastle/asn1/StreamUtil;
.super Ljava/lang/Object;
.source "StreamUtil.java"


# static fields
.field private static final MAX_MEMORY:J


# direct methods
.method static constructor <clinit>()V
    .registers 2

    .prologue
    .line 11
    invoke-static {}, Ljava/lang/Runtime;->getRuntime()Ljava/lang/Runtime;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/Runtime;->maxMemory()J

    move-result-wide v0

    sput-wide v0, Lorg/spongycastle/asn1/StreamUtil;->MAX_MEMORY:J

    return-void
.end method

.method constructor <init>()V
    .registers 1

    .prologue
    .line 9
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

.method static calculateBodyLength(I)I
    .registers 3

    .prologue
    const/4 v0, 0x1

    .line 62
    .line 64
    const/16 v1, 0x7f

    if-le p0, v1, :cond_18

    move v1, v0

    .line 69
    :goto_6
    ushr-int/lit8 p0, p0, 0x8

    if-eqz p0, :cond_d

    .line 71
    add-int/lit8 v1, v1, 0x1

    goto :goto_6

    .line 74
    :cond_d
    add-int/lit8 v1, v1, -0x1

    shl-int/lit8 v1, v1, 0x3

    :goto_11
    if-ltz v1, :cond_18

    .line 76
    add-int/lit8 v0, v0, 0x1

    .line 74
    add-int/lit8 v1, v1, -0x8

    goto :goto_11

    .line 80
    :cond_18
    return v0
.end method

.method static calculateTagLength(I)I
    .registers 4

    .prologue
    const/4 v0, 0x4

    .line 86
    const/4 v1, 0x1

    .line 88
    const/16 v2, 0x1f

    if-lt p0, v2, :cond_28

    .line 90
    const/16 v1, 0x80

    if-ge p0, v1, :cond_c

    .line 92
    const/4 v0, 0x2

    .line 112
    :goto_b
    return v0

    .line 96
    :cond_c
    const/4 v1, 0x5

    new-array v1, v1, [B

    .line 99
    and-int/lit8 v2, p0, 0x7f

    int-to-byte v2, v2

    aput-byte v2, v1, v0

    .line 103
    :cond_14
    shr-int/lit8 p0, p0, 0x7

    .line 104
    add-int/lit8 v0, v0, -0x1

    and-int/lit8 v2, p0, 0x7f

    or-int/lit16 v2, v2, 0x80

    int-to-byte v2, v2

    aput-byte v2, v1, v0

    .line 106
    const/16 v2, 0x7f

    if-gt p0, v2, :cond_14

    .line 108
    rsub-int/lit8 v0, v0, 0x5

    add-int/lit8 v0, v0, 0x1

    goto :goto_b

    :cond_28
    move v0, v1

    goto :goto_b
.end method

.method static findLimit(Ljava/io/InputStream;)I
    .registers 6

    .prologue
    const-wide/32 v2, 0x7fffffff

    .line 21
    instance-of v0, p0, Lorg/spongycastle/asn1/LimitedInputStream;

    if-eqz v0, :cond_e

    .line 23
    check-cast p0, Lorg/spongycastle/asn1/LimitedInputStream;

    invoke-virtual {p0}, Lorg/spongycastle/asn1/LimitedInputStream;->getRemaining()I

    move-result v0

    .line 56
    :goto_d
    return v0

    .line 25
    :cond_e
    instance-of v0, p0, Lorg/spongycastle/asn1/ASN1InputStream;

    if-eqz v0, :cond_19

    .line 27
    check-cast p0, Lorg/spongycastle/asn1/ASN1InputStream;

    invoke-virtual {p0}, Lorg/spongycastle/asn1/ASN1InputStream;->getLimit()I

    move-result v0

    goto :goto_d

    .line 29
    :cond_19
    instance-of v0, p0, Ljava/io/ByteArrayInputStream;

    if-eqz v0, :cond_24

    .line 31
    check-cast p0, Ljava/io/ByteArrayInputStream;

    invoke-virtual {p0}, Ljava/io/ByteArrayInputStream;->available()I

    move-result v0

    goto :goto_d

    .line 33
    :cond_24
    instance-of v0, p0, Ljava/io/FileInputStream;

    if-eqz v0, :cond_3d

    .line 37
    :try_start_28
    check-cast p0, Ljava/io/FileInputStream;

    invoke-virtual {p0}, Ljava/io/FileInputStream;->getChannel()Ljava/nio/channels/FileChannel;

    move-result-object v0

    .line 38
    if-eqz v0, :cond_3a

    invoke-virtual {v0}, Ljava/nio/channels/FileChannel;->size()J
    :try_end_33
    .catch Ljava/io/IOException; {:try_start_28 .. :try_end_33} :catch_3c

    move-result-wide v0

    .line 40
    :goto_34
    cmp-long v4, v0, v2

    if-gez v4, :cond_3d

    .line 42
    long-to-int v0, v0

    goto :goto_d

    :cond_3a
    move-wide v0, v2

    .line 38
    goto :goto_34

    :catch_3c
    move-exception v0

    .line 51
    :cond_3d
    sget-wide v0, Lorg/spongycastle/asn1/StreamUtil;->MAX_MEMORY:J

    cmp-long v0, v0, v2

    if-lez v0, :cond_47

    .line 53
    const v0, 0x7fffffff

    goto :goto_d

    .line 56
    :cond_47
    sget-wide v0, Lorg/spongycastle/asn1/StreamUtil;->MAX_MEMORY:J

    long-to-int v0, v0

    goto :goto_d
.end method