~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/asn1/test/testCompactBitString.erl

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%%
 
4
%% Copyright Ericsson AB 2001-2010. All Rights Reserved.
 
5
%%
 
6
%% The contents of this file are subject to the Erlang Public License,
 
7
%% Version 1.1, (the "License"); you may not use this file except in
 
8
%% compliance with the License. You should have received a copy of the
 
9
%% Erlang Public License along with this software. If not, it can be
 
10
%% retrieved online at http://www.erlang.org/.
 
11
%%
 
12
%% Software distributed under the License is distributed on an "AS IS"
 
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
%% the License for the specific language governing rights and limitations
 
15
%% under the License.
 
16
%%
 
17
%% %CopyrightEnd%
 
18
%%
 
19
%%
 
20
-module(testCompactBitString).
 
21
 
 
22
-export([compile/3]).
 
23
-export([compact_bit_string/1, bit_string_unnamed/1,otp_4869/1,
 
24
         ticket_7734/1]).
 
25
 
 
26
-include_lib("test_server/include/test_server.hrl").
 
27
 
 
28
 
 
29
compile(Config,Rules,Option) ->
 
30
 
 
31
    ?line DataDir = ?config(data_dir,Config),
 
32
    ?line OutDir = ?config(priv_dir,Config),
 
33
    ?line true = code:add_patha(?config(priv_dir,Config)),
 
34
    ?line ok = asn1ct:compile(DataDir ++ "PrimStrings",
 
35
                              [Rules,{outdir,OutDir}]++Option),
 
36
    case Rules of
 
37
        per_bin ->
 
38
            ?line ok = asn1ct:compile(DataDir ++ "Constraints",
 
39
                                      [Rules,{outdir,OutDir}]++Option);
 
40
        _ ->  ok
 
41
    end.
 
42
 
 
43
 
 
44
 
 
45
compact_bit_string(Rules) ->
 
46
 
 
47
    %%==========================================================
 
48
    %% Bs1 ::= BIT STRING
 
49
    %%==========================================================
 
50
 
 
51
    ?line {ok,Bytes1} = asn1_wrapper:encode('PrimStrings','Bs1',0),
 
52
    ?line {ok,{0,<<>>}} = 
 
53
        asn1_wrapper:decode('PrimStrings','Bs1',lists:flatten(Bytes1)),
 
54
    
 
55
    ?line {ok,Bytes2} = asn1_wrapper:encode('PrimStrings','Bs1',4),
 
56
    ?line {ok,{5,<<32>>}} = 
 
57
        asn1_wrapper:decode('PrimStrings','Bs1',lists:flatten(Bytes2)),
 
58
    
 
59
    ?line {ok,Bytes3} = asn1_wrapper:encode('PrimStrings','Bs1',15),
 
60
    ?line {ok,{4,<<240>>}} = 
 
61
        asn1_wrapper:decode('PrimStrings','Bs1',
 
62
                            lists:flatten(Bytes3)),
 
63
    
 
64
    ?line {ok,Bytes4} = asn1_wrapper:encode('PrimStrings','Bs1',255),
 
65
    ?line {ok,{0,<<255>>}} = 
 
66
        asn1_wrapper:decode('PrimStrings','Bs1',lists:flatten(Bytes4)),
 
67
            
 
68
    ?line {ok,Bytes5} = asn1_wrapper:encode('PrimStrings','Bs1',256),
 
69
    ?line {ok,{7,<<0,128>>}} = 
 
70
        asn1_wrapper:decode('PrimStrings','Bs1',lists:flatten(Bytes5)),
 
71
    
 
72
    ?line {ok,Bytes6} = asn1_wrapper:encode('PrimStrings','Bs1',257),
 
73
    ?line {ok,{7,<<128,128>>}} = 
 
74
        asn1_wrapper:decode('PrimStrings','Bs1',
 
75
                            lists:flatten(Bytes6)),
 
76
    
 
77
    ?line {ok,Bytes7} = asn1_wrapper:encode('PrimStrings','Bs1',444),
 
78
    ?line {ok,{7,<<61,128>>}} = 
 
79
        asn1_wrapper:decode('PrimStrings','Bs1',
 
80
                            lists:flatten(Bytes7)),
 
81
    
 
82
    ?line {ok,Bytes8} = asn1_wrapper:encode('PrimStrings','Bs1',
 
83
                                            12345678901234567890),
 
84
    ?line {ok,_} = asn1_wrapper:decode('PrimStrings','Bs1',
 
85
                                       lists:flatten(Bytes8)),
 
86
    
 
87
%% Removed due to beam cannot handle this big integers    
 
88
%%    Bs1_1 = 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
 
89
%%    ?line {ok,Bytes9} = asn1_wrapper:encode('PrimStrings','Bs1',Bs1_1),
 
90
%%    ?line {ok,_} = asn1_wrapper:decode('PrimStrings','Bs1',lists:flatten(Bytes9)),
 
91
    
 
92
%%    Bs1_2 = 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890,
 
93
%%    ?line {ok,Bytes10} = asn1_wrapper:encode('PrimStrings','Bs1',Bs1_2),
 
94
%%    ?line {ok,_} = asn1_wrapper:decode('PrimStrings','Bs1',lists:flatten(Bytes10)),
 
95
    
 
96
    ?line {ok,Bytes11} = asn1_wrapper:encode('PrimStrings','Bs1',
 
97
                                             [1,1,1,1,1,1,1,1]),
 
98
    ?line {ok,{0,<<255>>}} = asn1_wrapper:decode('PrimStrings','Bs1',
 
99
                                                 lists:flatten(Bytes11)),
 
100
    
 
101
    ?line {ok,Bytes12} = asn1_wrapper:encode('PrimStrings',
 
102
                                             'Bs1',
 
103
                                             [0,1,0,0,1,0]),
 
104
    ?line {ok,{2,<<72>>}} = 
 
105
        asn1_wrapper:decode('PrimStrings','Bs1',
 
106
                            lists:flatten(Bytes12)),
 
107
    
 
108
    ?line {ok,Bytes13} = 
 
109
        asn1_wrapper:encode('PrimStrings', 'Bs1',
 
110
                            [1,0,0,0,0,0,0,0,0]),
 
111
    ?line {ok,{7,<<128,0>>}} = 
 
112
        asn1_wrapper:decode('PrimStrings','Bs1',
 
113
                            lists:flatten(Bytes13)),
 
114
    
 
115
    
 
116
    ?line {ok,Bytes14} = 
 
117
        asn1_wrapper:encode('PrimStrings','Bs1',
 
118
                            [0,1,0,0,1,0,1,1,1,1,1,0,0,0,1,0,0,1,1]),
 
119
    ?line {ok,{5,<<75,226,96>>}} = 
 
120
        asn1_wrapper:decode('PrimStrings','Bs1',lists:flatten(Bytes14)),
 
121
    
 
122
    
 
123
    ?line case asn1_wrapper:erule(Rules) of
 
124
              ber -> 
 
125
                  ?line Bytes15 = [35,8,3,2,0,73,3,2,4,32],
 
126
                  ?line {ok,{4,<<73,32>>}} = 
 
127
                      asn1_wrapper:decode('PrimStrings','Bs1',
 
128
                                          lists:flatten(Bytes15)),
 
129
                  
 
130
                  ?line Bytes16 = [35,9,3,2,0,234,3,3,7,156,0],
 
131
                  ?line {ok,{7,<<234,156,0>>}} = 
 
132
                      asn1_wrapper:decode('PrimStrings','Bs1',
 
133
                                          lists:flatten(Bytes16)),
 
134
                  
 
135
                  ?line Bytes17 = [35,128,3,2,0,73,3,2,4,32,0,0],
 
136
                  ?line {ok,{4,<<73,32>>}} = 
 
137
                      asn1_wrapper:decode('PrimStrings','Bs1',
 
138
                                          lists:flatten(Bytes17)),
 
139
                  
 
140
                  ?line Bytes18 = [35,128,3,2,0,234,3,3,7,156,0,0,0],
 
141
                  ?line {ok,{7,<<234,156,0>>}} = 
 
142
                      asn1_wrapper:decode('PrimStrings','Bs1',
 
143
                                          lists:flatten(Bytes18)),
 
144
                  ok;
 
145
              
 
146
              per ->
 
147
                  ok
 
148
          end,
 
149
    
 
150
    %% The following case to test OTP-4200
 
151
     ?line {ok,Bytes19} = 
 
152
        asn1_wrapper:encode('PrimStrings','Bs1',{0,<<0,0,1,1>>}),
 
153
    ?line {ok,{0,<<0,0,1,1>>}} = 
 
154
        asn1_wrapper:decode('PrimStrings','Bs1',lists:flatten(Bytes19)),
 
155
 
 
156
    %%==========================================================
 
157
    %% Bs2 ::= BIT STRING {su(0), mo(1), tu(2), we(3), th(4), fr(5), sa(6) } (SIZE (7))
 
158
    %%==========================================================
 
159
    
 
160
    ?line {ok,Bytes21} = asn1_wrapper:encode('PrimStrings','Bs2',[mo,tu,fr]),
 
161
    ?line {ok,[mo,tu,fr]} = asn1_wrapper:decode('PrimStrings','Bs2',lists:flatten(Bytes21)),
 
162
    
 
163
    ?line {ok,Bytes22} = asn1_wrapper:encode('PrimStrings','Bs2',[0,1,1,0,0,1,0]),
 
164
    ?line {ok,[mo,tu,fr]} = asn1_wrapper:decode('PrimStrings','Bs2',lists:flatten(Bytes22)),
 
165
    
 
166
    % ?line case asn1_wrapper:erule(Rules) of
 
167
%             ber -> 
 
168
%                 ?line {ok,[mo,tu,fr,su,mo,th]} = 
 
169
%                     asn1_wrapper:decode('PrimStrings','Bs2',[35,8,3,2,1,100,3,2,2,200]),
 
170
                  
 
171
%                 ?line {ok,[mo,tu,fr,su,mo,th]} = 
 
172
%                     asn1_wrapper:decode('PrimStrings','Bs2',[35,128,3,2,1,100,3,2,2,200,0,0]),
 
173
%                 ok;
 
174
              
 
175
%             per ->
 
176
%                 ok
 
177
%         end,
 
178
    
 
179
    
 
180
    
 
181
    %%==========================================================
 
182
    %% Bs3 ::= BIT STRING {su(0), mo(1), tu(2), we(3), th(4), fr(5), sa(6) } (SIZE (1..7))
 
183
    %%==========================================================
 
184
    
 
185
    ?line {ok,Bytes31} = asn1_wrapper:encode('PrimStrings','Bs3',[mo,tu,fr]),
 
186
    ?line {ok,[mo,tu,fr]} = asn1_wrapper:decode('PrimStrings','Bs3',lists:flatten(Bytes31)),
 
187
    
 
188
    ?line {ok,Bytes32} = asn1_wrapper:encode('PrimStrings','Bs3',[0,1,1,0,0,1,0]),
 
189
    ?line {ok,[mo,tu,fr]} = asn1_wrapper:decode('PrimStrings','Bs3',lists:flatten(Bytes32)),
 
190
    
 
191
    
 
192
    
 
193
    %%==========================================================
 
194
    %% BsPri ::= [PRIVATE 61] BIT STRING
 
195
    %%==========================================================
 
196
    
 
197
    ?line {ok,Bytes41} = asn1_wrapper:encode('PrimStrings','BsPri',45),
 
198
    ?line {ok,{2,<<180>>}} = 
 
199
        asn1_wrapper:decode('PrimStrings','BsPri',lists:flatten(Bytes41)),
 
200
    
 
201
    ?line {ok,Bytes42} = asn1_wrapper:encode('PrimStrings','BsPri',211),
 
202
    ?line {ok,{0,<<203>>}} = 
 
203
        asn1_wrapper:decode('PrimStrings','BsPri',lists:flatten(Bytes42)),
 
204
    
 
205
    ?line case asn1_wrapper:erule(Rules) of
 
206
              ber -> 
 
207
                  ?line {ok,{5,<<75,226,96>>}} = 
 
208
                      asn1_wrapper:decode('PrimStrings','BsPri',
 
209
                                          [223,61,4,5,75,226,96]),
 
210
                  
 
211
                  ?line {ok,{5,<<75,226,96>>}} = 
 
212
                      asn1_wrapper:decode('PrimStrings','BsPri',
 
213
                                          [255,61,128,3,4,5,75,226,96,0,0]),
 
214
                  
 
215
                  ?line {ok,{5,<<75,226,96>>}} = 
 
216
                      asn1_wrapper:decode('PrimStrings','BsPri',
 
217
                                          [255,61,9,3,2,0,75,3,3,5,226,96]),
 
218
                  
 
219
                  ?line {ok,{5,<<75,226,96>>}} = 
 
220
                      asn1_wrapper:decode('PrimStrings','BsPri',
 
221
                                          [255,61,128,3,2,0,75,3,3,5,226,96,0,0]),
 
222
                  ok;
 
223
              
 
224
              per ->
 
225
                  ok
 
226
          end,
 
227
    
 
228
    
 
229
    
 
230
    %%==========================================================
 
231
    %% BsExpPri ::= [PRIVATE 61] EXPLICIT BIT STRING
 
232
    %%==========================================================
 
233
    
 
234
    ?line {ok,Bytes51} = asn1_wrapper:encode('PrimStrings','BsExpPri',45),
 
235
    ?line {ok,{2,<<180>>}} = 
 
236
        asn1_wrapper:decode('PrimStrings','BsExpPri',lists:flatten(Bytes51)),
 
237
    
 
238
    ?line {ok,Bytes52} = asn1_wrapper:encode('PrimStrings','BsExpPri',211),
 
239
    ?line {ok,{0,<<203>>}} = 
 
240
        asn1_wrapper:decode('PrimStrings','BsExpPri',lists:flatten(Bytes52)),
 
241
    
 
242
    ?line case asn1_wrapper:erule(Rules) of
 
243
              ber -> 
 
244
                  ?line {ok,{5,<<75,226,96>>}} = 
 
245
                      asn1_wrapper:decode('PrimStrings','BsExpPri',[255,61,6,3,4,5,75,226,96]),
 
246
                  ok;
 
247
              
 
248
              per ->
 
249
                  ok
 
250
          end,
 
251
    
 
252
    ok.
 
253
 
 
254
ticket_7734(per_bin) ->
 
255
    ?line BS = {0,list_to_binary(lists:duplicate(128,0))},
 
256
    ?line {ok,BSEnc} = asn1_wrapper:encode('PrimStrings','BS1024',BS),
 
257
    ?line {ok,BS} = asn1_wrapper:decode('PrimStrings','BS1024',BSEnc).
 
258
 
 
259
bit_string_unnamed(Rules) ->
 
260
    case asn1_wrapper:erule(Rules) of
 
261
        ber ->
 
262
            ok;
 
263
        per ->
 
264
            ?line {ok,Bytes1} = 
 
265
                asn1_wrapper:encode('PrimStrings','TransportLayerAddress',
 
266
                                    [0,1,1,0]),
 
267
            ?line {ok,{4,<<96>>}} = 
 
268
                asn1_wrapper:decode('PrimStrings','TransportLayerAddress',
 
269
                                    lists:flatten(Bytes1))
 
270
    end.
 
271
 
 
272
otp_4869(per_bin) ->
 
273
    ?line Val1={'IP',[0],{0,<<62,235,90,50,0,0,0,0,0,0,0,0,0,0,0,0>>},asn1_NOVALUE},
 
274
    ?line Val2 = {'IP',[0],[0,0,1,1,1,1,1,0,1,1,1,0,1,0,1,1,0,1,0,1,1,0,1,0,0,0,1,1,0,0,1,0] ++ lists:duplicate(128 - 32,0),asn1_NOVALUE},
 
275
 
 
276
    ?line {ok,Bytes1} = asn1_wrapper:encode('Constraints','IP',Val1),
 
277
    ?line {ok,Bytes1} = asn1_wrapper:encode('Constraints','IP',Val2);
 
278
otp_4869(_) ->
 
279
    ok.