From 6524db299d01e4041f02de15c1bb8eb2922408b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Wed, 19 Dec 2012 07:24:58 +0100 Subject: Add and use asn1rtt_ext --- lib/asn1/src/Makefile | 1 + lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl | 11 ++-- lib/asn1/src/asn1ct_constructed_per.erl | 13 ++--- lib/asn1/src/asn1rtt_ext.erl | 69 ++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 lib/asn1/src/asn1rtt_ext.erl (limited to 'lib/asn1/src') diff --git a/lib/asn1/src/Makefile b/lib/asn1/src/Makefile index a9806c13a4..b54627a9b3 100644 --- a/lib/asn1/src/Makefile +++ b/lib/asn1/src/Makefile @@ -174,6 +174,7 @@ release_docs_spec: # RT_TEMPLATES = asn1rtt_check \ + asn1rtt_ext \ asn1rtt_per_common \ asn1rtt_real_common \ asn1rtt_ber \ diff --git a/lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl b/lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl index 021002c3b3..d5097e83c5 100644 --- a/lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl +++ b/lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl @@ -66,9 +66,9 @@ gen_encode_sequence(Erules,Typename,D) when is_record(D,type) -> ValName = case Typename of ['EXTERNAL'] -> - emit([indent(4), - "NewVal = asn1rt_check:transform_to_EXTERNAL1990(Val),", - nl]), + emit([indent(4),"NewVal = ", + {call,ext,transform_to_EXTERNAL1990,["Val"]}, + com,nl]), "NewVal"; _ -> "Val" @@ -289,8 +289,9 @@ gen_decode_sequence(Erules,Typename,D) when is_record(D,type) -> "', "]), mkvlist(asn1ct_name:all(term)), emit(["},",nl]), - emit([" asn1rt_check:transform_to_EXTERNAL1994", - "(OldFormat).",nl]); + emit([" ", + {call,ext,transform_to_EXTERNAL1994, + ["OldFormat"]},".",nl]); _ -> emit([" {'",RecordName,"', "]), mkvlist(asn1ct_name:all(term)), diff --git a/lib/asn1/src/asn1ct_constructed_per.erl b/lib/asn1/src/asn1ct_constructed_per.erl index 5520b41541..c3aa482051 100644 --- a/lib/asn1/src/asn1ct_constructed_per.erl +++ b/lib/asn1/src/asn1ct_constructed_per.erl @@ -67,9 +67,9 @@ gen_encode_constructed(Erule,Typename,D) when is_record(D,type) -> end, case Typename of ['EXTERNAL'] -> - emit({{next,val}, - " = asn1rt_check:transform_to_EXTERNAL1990(", - {curr,val},"),",nl}), + emit([{next,val}," = ", + {call,ext,transform_to_EXTERNAL1990, + [{curr,val}]},com,nl]), asn1ct_name:new(val); _ -> ok @@ -386,9 +386,10 @@ gen_dec_constructed_imm_2(Typename, CompList, "'"}), mkvlist(asn1ct_name:all(term)), emit({"},",nl}), - emit({" ASN11994Format =",nl, - " asn1rt_check:transform_to_EXTERNAL1994", - "(OldFormat),",nl}), + emit([" ASN11994Format =",nl, + " ", + {call,ext,transform_to_EXTERNAL1994, + ["OldFormat"]},com,nl]), emit(" {ASN11994Format,"); _ -> emit(["{{'",RecordName,"'"]), diff --git a/lib/asn1/src/asn1rtt_ext.erl b/lib/asn1/src/asn1rtt_ext.erl new file mode 100644 index 0000000000..59dbcc16bd --- /dev/null +++ b/lib/asn1/src/asn1rtt_ext.erl @@ -0,0 +1,69 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2012. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% + +-module(asn1rtt_ext). +-export([transform_to_EXTERNAL1990/1,transform_to_EXTERNAL1994/1]). + +transform_to_EXTERNAL1990({_,_,_,_}=Val) -> + transform_to_EXTERNAL1990(tuple_to_list(Val), []); +transform_to_EXTERNAL1990(Val) when is_tuple(Val) -> + %% Data already in ASN1 1990 format + Val. + +transform_to_EXTERNAL1990(['EXTERNAL'|Rest], Acc) -> + transform_to_EXTERNAL1990(Rest, ['EXTERNAL'|Acc]); +transform_to_EXTERNAL1990([{syntax,Syntax}|Rest], Acc) -> + transform_to_EXTERNAL1990(Rest, [asn1_NOVALUE,Syntax|Acc]); +transform_to_EXTERNAL1990([{'presentation-context-id',PCid}|Rest], Acc) -> + transform_to_EXTERNAL1990(Rest, [PCid,asn1_NOVALUE|Acc]); +transform_to_EXTERNAL1990([{'context-negotiation',Context_negot}|Rest], Acc) -> + {_,Presentation_Cid,Transfer_syntax} = Context_negot, + transform_to_EXTERNAL1990(Rest, [Presentation_Cid,Transfer_syntax|Acc]); +transform_to_EXTERNAL1990([asn1_NOVALUE|Rest], Acc) -> + transform_to_EXTERNAL1990(Rest, [asn1_NOVALUE|Acc]); +transform_to_EXTERNAL1990([Data_val_desc,Data_value], Acc) + when is_list(Data_value)-> + list_to_tuple(lists:reverse([{'octet-aligned',Data_value}, + Data_val_desc|Acc])); +transform_to_EXTERNAL1990([Data_val_desc,Data_value], Acc) + when is_binary(Data_value) -> + list_to_tuple(lists:reverse([{'single-ASN1-type',Data_value}, + Data_val_desc|Acc])); +transform_to_EXTERNAL1990([Data_value], Acc) + when is_list(Data_value); is_binary(Data_value) -> + list_to_tuple(lists:reverse([{'octet-aligned',Data_value}|Acc])). + + +transform_to_EXTERNAL1994({'EXTERNAL',DRef,IndRef,Data_v_desc,Encoding}=V) -> + Identification = + case {DRef,IndRef} of + {DRef,asn1_NOVALUE} -> + {syntax,DRef}; + {asn1_NOVALUE,IndRef} -> + {'presentation-context-id',IndRef}; + _ -> + {'context-negotiation', + {'EXTERNAL_identification_context-negotiation',IndRef,DRef}} + end, + case Encoding of + {_,Val} when is_list(Val); is_binary(Val) -> + {'EXTERNAL',Identification,Data_v_desc,Val}; + _ -> + V + end. -- cgit v1.2.3