aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src/asn1ct_check.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2014-01-21 16:12:46 +0100
committerBjörn Gustavsson <[email protected]>2014-01-24 16:24:56 +0100
commitaaa4ea283b2b7dad74fdcdd5963558e9d03d80b0 (patch)
tree765382e19e86d86a897daec07e7335571285966d /lib/asn1/src/asn1ct_check.erl
parent4bda9201055daf3abbdb5ef48bbdd0efacfd1fbc (diff)
downloadotp-aaa4ea283b2b7dad74fdcdd5963558e9d03d80b0.tar.gz
otp-aaa4ea283b2b7dad74fdcdd5963558e9d03d80b0.tar.bz2
otp-aaa4ea283b2b7dad74fdcdd5963558e9d03d80b0.zip
Fix OCTET STRING
Diffstat (limited to 'lib/asn1/src/asn1ct_check.erl')
-rw-r--r--lib/asn1/src/asn1ct_check.erl45
1 files changed, 14 insertions, 31 deletions
diff --git a/lib/asn1/src/asn1ct_check.erl b/lib/asn1/src/asn1ct_check.erl
index 0a13801e08..f94f3b56bc 100644
--- a/lib/asn1/src/asn1ct_check.erl
+++ b/lib/asn1/src/asn1ct_check.erl
@@ -2574,6 +2574,18 @@ normalize_bitstring(S, Value, Type)->
Bs
end.
+hstring_to_binary(L) ->
+ byte_align(hstring_to_bitstring(L)).
+
+bstring_to_binary(L) ->
+ byte_align(bstring_to_bitstring(L)).
+
+byte_align(Bs) ->
+ case bit_size(Bs) rem 8 of
+ 0 -> Bs;
+ N -> <<Bs/bitstring,0:(8-N)>>
+ end.
+
hstring_to_bitstring(L) ->
<< <<(hex_to_int(D)):4>> || D <- L >>.
@@ -2592,9 +2604,9 @@ hex_to_int(D) when $A =< D, D =< $F -> D - ($A - 10).
normalize_octetstring(S,Value,CType) ->
case Value of
{bstring,String} ->
- bstring_to_octetlist(String);
+ bstring_to_binary(String);
{hstring,String} ->
- hstring_to_octetlist(String);
+ hstring_to_binary(String);
Rec when is_record(Rec,'Externalvaluereference') ->
get_normalized_value(S,Value,CType,
fun normalize_octetstring/3,[]);
@@ -2616,35 +2628,6 @@ normalize_octetstring(S,Value,CType) ->
Value
end.
-
-bstring_to_octetlist([]) ->
- [];
-bstring_to_octetlist([H|T]) when H == $0 ; H == $1 ->
- bstring_to_octetlist(T,6,[(H - $0) bsl 7]).
-bstring_to_octetlist([H|T],0,[Hacc|Tacc]) when H == $0; H == $1 ->
- bstring_to_octetlist(T, 7, [0,Hacc + (H -$0)| Tacc]);
-bstring_to_octetlist([H|T],BSL,[Hacc|Tacc]) when H == $0; H == $1 ->
- bstring_to_octetlist(T, BSL-1, [Hacc + ((H - $0) bsl BSL)| Tacc]);
-bstring_to_octetlist([],7,[0|Acc]) ->
- lists:reverse(Acc);
-bstring_to_octetlist([],_,Acc) ->
- lists:reverse(Acc).
-
-hstring_to_octetlist([]) ->
- [];
-hstring_to_octetlist(L) ->
- hstring_to_octetlist(L,4,[]).
-hstring_to_octetlist([H|T],0,[Hacc|Tacc]) when H >= $A, H =< $F ->
- hstring_to_octetlist(T,4,[Hacc + (H - $A + 10)|Tacc]);
-hstring_to_octetlist([H|T],BSL,Acc) when H >= $A, H =< $F ->
- hstring_to_octetlist(T,0,[(H - $A + 10) bsl BSL|Acc]);
-hstring_to_octetlist([H|T],0,[Hacc|Tacc]) when H >= $0; H =< $9 ->
- hstring_to_octetlist(T,4,[Hacc + (H - $0)|Tacc]);
-hstring_to_octetlist([H|T],BSL,Acc) when H >= $0; H =< $9 ->
- hstring_to_octetlist(T,0,[(H - $0) bsl BSL|Acc]);
-hstring_to_octetlist([],_,Acc) ->
- lists:reverse(Acc).
-
normalize_objectidentifier(S, Value) ->
{ok,Val} = validate_objectidentifier(S, o_id, Value, []),
Val.