Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:19
erlang
0856-Make-hstring-bstring-lexical-items-conform...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0856-Make-hstring-bstring-lexical-items-conform-to-ITU-T-.patch of Package erlang
From c8227bc56231eaed325be9080647339845e79b14 Mon Sep 17 00:00:00 2001 From: Simon Cornish <zl9d97p02@sneakemail.com> Date: Sun, 9 Feb 2020 23:00:15 -0800 Subject: [PATCH] Make hstring & bstring lexical items conform to ITU-T X.680 (08/2015) --- lib/asn1/src/asn1ct_tok.erl | 55 ++++++++++++++++------------- lib/asn1/test/asn1_SUITE_data/ValueTest.asn | 2 ++ lib/asn1/test/testValueTest.erl | 2 ++ 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/lib/asn1/src/asn1ct_tok.erl b/lib/asn1/src/asn1ct_tok.erl index 8235b689f8..76ff60f9cf 100644 --- a/lib/asn1/src/asn1ct_tok.erl +++ b/lib/asn1/src/asn1ct_tok.erl @@ -239,16 +239,16 @@ skip_multiline_comment(Stream, [_|T], Lno, Level) -> skip_multiline_comment(Stream, T, Lno, Level). collect_quoted("'B"++T, Lno, L) -> - case check_bin(L) of - true -> - {{bstring,Lno,lists:reverse(L)}, T}; + case validate_bin(L) of + {ok, Bin} -> + {{bstring,Lno,Bin}, T}; false -> throw({error,{invalid_binary_number,lists:reverse(L)}}) end; collect_quoted("'H"++T, Lno, L) -> - case check_hex(L) of - true -> - {{hstring,Lno,lists:reverse(L)}, T}; + case validate_hex(L) of + {ok, Hex} -> + {{hstring,Lno,Hex}, T}; false -> throw({error,{invalid_hex_number,lists:reverse(L)}}) end; @@ -257,24 +257,31 @@ collect_quoted([H|T], Lno, L) -> collect_quoted([], _, _) -> % This should be allowed FIX later throw({error,eol_in_token}). -check_bin([$0|T]) -> - check_bin(T); -check_bin([$1|T]) -> - check_bin(T); -check_bin([]) -> - true; -check_bin(_) -> - false. - -check_hex([H|T]) when $0 =< H , H =< $9 -> - check_hex(T); -check_hex([H|T]) when $A =< H , H =< $F -> - check_hex(T); -check_hex([]) -> - true; -check_hex(_) -> - false. - +validate_bin(L) -> + validate_bin(L,[]). + +validate_bin([H|T], A) when H =:= $0; H =:= $1 -> + validate_bin(T, [H|A]); +validate_bin([$\s|T], A) -> + validate_bin(T, A); +validate_bin([_|_], _) -> + false; +validate_bin([], A) -> + {ok, A}. + +validate_hex(L) -> + validate_hex(L,[]). + +validate_hex([H|T], A) when $0 =< H , H =< $9 -> + validate_hex(T, [H|A]); +validate_hex([H|T], A) when $A =< H , H =< $F -> + validate_hex(T, [H|A]); +validate_hex([$\s|T], A) -> + validate_hex(T, A); +validate_hex([_|_], _) -> + false; +validate_hex([], A) -> + {ok, A}. %% reserved_word(A) -> true|false|rstrtype %% A = atom() diff --git a/lib/asn1/test/asn1_SUITE_data/ValueTest.asn b/lib/asn1/test/asn1_SUITE_data/ValueTest.asn index b2c59d686a..0474386061 100644 --- a/lib/asn1/test/asn1_SUITE_data/ValueTest.asn +++ b/lib/asn1/test/asn1_SUITE_data/ValueTest.asn @@ -100,6 +100,7 @@ os-holder-1 OS-HOLDER ::= { ID 1 OS '4041FF'H } OctetStringSeq ::= ParamSeq{OCTET STRING} someOctetString OCTET STRING ::= '404142'H +someOctetStringWhiteSpace OCTET STRING ::= '40 41 42'H octetStringSeq1 OctetStringSeq ::= { a someOctetString } octetStringSeq2 OctetStringSeq ::= { a otherOctetString } @@ -128,6 +129,7 @@ BsSeq ::= SEQUENCE { } someBitString BIT STRING ::= '101101'B +someBitStringWhiteSpace BIT STRING ::= '101 101'B bsSeq1 BsSeq ::= { a someBitString, b someNamedBs } bsSeq2 BsSeq ::= { a otherBitString, b someOtherNamedBs } diff --git a/lib/asn1/test/testValueTest.erl b/lib/asn1/test/testValueTest.erl index 6699c0094a..f09a9ee307 100644 --- a/lib/asn1/test/testValueTest.erl +++ b/lib/asn1/test/testValueTest.erl @@ -84,6 +84,7 @@ main() -> {'OctetStringSeq',<<16#40,16#41,16#42>>} = M:octetStringSeq1(), <<16#40,16#41,16#42>> = M:otherOctetString(), <<16#40,16#41,16#42>> = M:someOctetString(), + <<16#40,16#41,16#42>> = M:someOctetStringWhiteSpace(), {'OctetStringSeq',<<16#40,16#41,16#42>>} = M:octetStringSeq2(), {'OctetStringSeq',<<16#40,16#41,16#FF>>} = M:octetStringSeq3(), <<16#40,16#41,16#FF>> = M:'os-1'(), @@ -94,6 +95,7 @@ main() -> {'BsSeq',<<2#101101:6>>,[c]} = M:bsSeq2(), {'BsSeq',<<2#101:3>>,[a,c]} = M:bsSeq3(), <<2#101101:6>> = M:someBitString(), + <<2#101101:6>> = M:someBitStringWhiteSpace(), <<2#101101:6>> = M:otherBitString(), <<2#101:3>> = M:bsFromObject(), <<2#101:3>> = M:bsFromObjectInd(), -- 2.16.4
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor