1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2014-2017. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20%% 21 22-module(testRfcs). 23 24-export([compile/3,test/0]). 25 26-include_lib("common_test/include/ct.hrl"). 27 28compile(Config, Erules, Options0) -> 29 Options = [no_ok_wrapper|Options0], 30 DataDir = proplists:get_value(data_dir, Config), 31 Specs0 = filelib:wildcard("*.asn1", filename:join(DataDir, rfcs)), 32 Specs = [filename:join(rfcs, Spec) || Spec <- Specs0], 33 122 = length(Specs), 34 CaseDir = proplists:get_value(case_dir, Config), 35 asn1_test_lib:compile_all(Specs, Config, [Erules,{i,CaseDir}|Options]). 36 37test() -> 38 M = 'OCSP-2009', 39 case M:maps() of 40 false -> 41 {1,3,6,1,5,5,7,48,1,2} = 42 IdPkixOcspNonce = 43 'OCSP-2009':'id-pkix-ocsp-nonce'(), 44 roundtrip('OCSP-2009', 'OCSPRequest', 45 {'OCSPRequest', 46 {'TBSRequest', 47 0, 48 {rfc822Name,"name string"}, 49 [{'Request', 50 {'CertID',{'_',{2,9,3,4,5},asn1_NOVALUE}, 51 <<"POTATOHASH">>,<<"HASHBROWN">>,42}, 52 [{'_',IdPkixOcspNonce,true,<<34,159,16,57,199>>}]}], 53 asn1_NOVALUE}, 54 asn1_NOVALUE}), 55 otp_7759(records); 56 true -> 57 otp_7759(maps) 58 end. 59 60roundtrip(Module, Type, Value0) -> 61 Enc = Module:encode(Type, Value0), 62 Value1 = Module:decode(Type, Enc), 63 asn1_test_lib:match_value(Value0, Value1), 64 ok. 65 66otp_7759(Pack) -> 67 %% The release note for asn-1.6.6 says: 68 %% Decode of an open_type when the value was empty tagged 69 %% type encoded with indefinite length failed. 70 Mod = 'OLD-PKCS7', 71 Encoded = encoded_msg(), 72 ContentInfo = Mod:decode('ContentInfo', Encoded), 73 io:format("~p\n", [ContentInfo]), 74 Content = case ContentInfo of 75 {'ContentInfo',_Id,Content0} when Pack =:= records -> 76 Content0; 77 #{'content-type':=_,'pkcs7-content':=Content0} 78 when Pack =:= maps -> 79 Content0 80 end, 81 X = Mod:decode('SignedData', Content), 82 io:format("~p\n", [X]), 83 ok. 84 85encoded_msg() -> 86 <<48,128,6,9,42,134,72,134,247,13,1,7,2,160,128,48,128,2,1,1,49,11,48,9,6,5,43,14,3,2,26,5,0,48,128,6,9,42,134,72,134,247,13,1,7,1,160,128,36,128,0,0,0,0,0,0, 49,130,1,192,48,130,1,188,2,1,1,48,50,48,38,49,17,48,15,6,3,85,4,3,12,8,65,100,109,105,110,67,65,49,49,17,48,15,6,3,85,4,10,12,8,69,82,73,67,83,83,79,78,2,8,15,151,245,186,21,23,240,96,48,9,6,5,43,14,3,2,26,5,0,160,129,229,48,17,6,10,96,134,72,1,134,248,69,1,9,2,49,3,19,1,51,48,17,6,10,96,134,72,1,134,248,69,1,9,3,49,3,19,1,51,48,24,6,9,42,134,72,134,247,13,1,9,3,49,11,6,9,42,134,72,134,247,13,1,7,1,48,28,6,9,42,134,72,134,247,13,1,9,5,49,15,23,13,48,56,49,50,49,48,48,57,53,52,50,51,90,48,28,6,10,96,134,72,1,134,248,69,1,9,7,49,14,19,12,49,53,50,56,49,52,50,52,48,57,53,53,48,32,6,10,96,134,72,1,134,248,69,1,9,5,49,18,4,16,165,115,177,71,78,88,239,113,78,56,98,98,18,202,217,235,48,32,6,10,96,134,72,1,134,248,69,1,9,6,49,18,4,16,227,174,230,251,43,153,252,65,11,93,231,83,34,18,55,46,48,35,6,9,42,134,72,134,247,13,1,9,4,49,22,4,20,218,57,163,238,94,107,75,13,50,85,191,239,149,96,24,144,175,216,7,9,48,13,6,9,42,134,72,134,247,13,1,1,1,5,0,4,129,128,106,233,116,125,140,51,133,173,63,41,54,138,214,211,89,215,169,125,98,77,16,222,216,240,211,79,125,111,87,186,73,63,253,204,107,102,177,63,174,197,224,212,231,172,149,246,33,68,223,67,102,93,64,152,152,5,216,102,247,134,36,197,150,236,57,77,56,138,95,71,204,31,23,149,241,213,78,172,165,249,100,187,12,45,19,57,67,120,54,63,15,239,41,217,127,61,254,60,201,104,68,3,135,214,206,93,253,255,192,94,56,107,68,210,57,61,41,249,47,156,130,244,52,12,163,216,236,69,0,0,0,0,0,0>>. 87