Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GeneralNameTest.java « test « asn1 « bouncycastle « org « java « test « src « core - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f88a83cdaa65bf2cc5c0745de08671d2b0cd6929 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package org.bouncycastle.asn1.test;

import org.bouncycastle.asn1.x509.GeneralName;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.encoders.Hex;
import org.bouncycastle.util.test.SimpleTest;

public class GeneralNameTest
    extends SimpleTest
{
    private static final byte[] ipv4 = Hex.decode("87040a090800");
    private static final byte[] ipv4WithMask1 = Hex.decode("87080a090800ffffff00");
    private static final byte[] ipv4WithMask2 = Hex.decode("87080a090800ffff8000");
    private static final byte[] ipv4WithMask3 = Hex.decode("87080a090800ffffc000");

    private static final byte[] ipv6a = Hex.decode("871020010db885a308d313198a2e03707334");
    private static final byte[] ipv6b = Hex.decode("871020010db885a3000013198a2e03707334");
    private static final byte[] ipv6c = Hex.decode("871000000000000000000000000000000001");
    private static final byte[] ipv6d = Hex.decode("871020010db885a3000000008a2e03707334");
    private static final byte[] ipv6e = Hex.decode("871020010db885a3000000008a2e0a090800");
    private static final byte[] ipv6f = Hex.decode("872020010db885a3000000008a2e0a090800ffffffffffff00000000000000000000");
    private static final byte[] ipv6g = Hex.decode("872020010db885a3000000008a2e0a090800ffffffffffffffffffffffffffffffff");
    private static final byte[] ipv6h = Hex.decode("872020010db885a300000000000000000000ffffffffffff00000000000000000000");
    private static final byte[] ipv6i = Hex.decode("872020010db885a300000000000000000000fffffffffffe00000000000000000000");
    private static final byte[] ipv6j = Hex.decode("872020010db885a300000000000000000000ffffffffffff80000000000000000000");

    public String getName()
    {
        return "GeneralName";
    }

    public void performTest()
        throws Exception
    {
        GeneralName nm = new GeneralName(GeneralName.iPAddress, "10.9.8.0");
        if (!Arrays.areEqual(nm.getEncoded(), ipv4))
        {
            fail("ipv4 encoding failed");
        }

        nm = new GeneralName(GeneralName.iPAddress, "10.9.8.0/255.255.255.0");
        if (!Arrays.areEqual(nm.getEncoded(), ipv4WithMask1))
        {
            fail("ipv4 with netmask 1 encoding failed");
        }

        nm = new GeneralName(GeneralName.iPAddress, "10.9.8.0/24");
        if (!Arrays.areEqual(nm.getEncoded(), ipv4WithMask1))
        {
            fail("ipv4 with netmask 2 encoding failed");
        }

        nm = new GeneralName(GeneralName.iPAddress, "10.9.8.0/255.255.128.0");
        if (!Arrays.areEqual(nm.getEncoded(), ipv4WithMask2))
        {
            fail("ipv4 with netmask 3a encoding failed");
        }

        nm = new GeneralName(GeneralName.iPAddress, "10.9.8.0/17");
        if (!Arrays.areEqual(nm.getEncoded(), ipv4WithMask2))
        {
            fail("ipv4 with netmask 3b encoding failed");
        }

        nm = new GeneralName(GeneralName.iPAddress, "10.9.8.0/255.255.192.0");
        if (!Arrays.areEqual(nm.getEncoded(), ipv4WithMask3))
        {
            fail("ipv4 with netmask 3a encoding failed");
        }

        nm = new GeneralName(GeneralName.iPAddress, "10.9.8.0/18");
        if (!Arrays.areEqual(nm.getEncoded(), ipv4WithMask3))
        {
            fail("ipv4 with netmask 3b encoding failed");
        }

        nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3:08d3:1319:8a2e:0370:7334");
        if (!Arrays.areEqual(nm.getEncoded(), ipv6a))
        {
            fail("ipv6 with netmask encoding failed");
        }

        nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::1319:8a2e:0370:7334");
        if (!Arrays.areEqual(nm.getEncoded(), ipv6b))
        {
            fail("ipv6b encoding failed");
        }

        nm = new GeneralName(GeneralName.iPAddress, "::1");
        if (!Arrays.areEqual(nm.getEncoded(), ipv6c))
        {
            fail("ipv6c failed");
        }

        nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::8a2e:0370:7334");
        if (!Arrays.areEqual(nm.getEncoded(), ipv6d))
        {
            fail("ipv6d failed");
        }

        nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::8a2e:10.9.8.0");
        if (!Arrays.areEqual(nm.getEncoded(), ipv6e))
        {
            fail("ipv6e failed");
        }

        nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::8a2e:10.9.8.0/ffff:ffff:ffff::0000");
        if (!Arrays.areEqual(nm.getEncoded(), ipv6f))
        {
            fail("ipv6f failed");
        }

        nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::8a2e:10.9.8.0/128");
        if (!Arrays.areEqual(nm.getEncoded(), ipv6g))
        {
            fail("ipv6g failed");
        }

        nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::/48");
        if (!Arrays.areEqual(nm.getEncoded(), ipv6h))
        {
            fail("ipv6h failed");
        }

        nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::/47");
        if (!Arrays.areEqual(nm.getEncoded(), ipv6i))
        {
            fail("ipv6i failed");
        }

        nm = new GeneralName(GeneralName.iPAddress, "2001:0db8:85a3::/49");
        if (!Arrays.areEqual(nm.getEncoded(), ipv6j))
        {
            fail("ipv6j failed");
        }
    }

    public static void main(
        String[] args)
    {
        runTest(new GeneralNameTest());
    }
}