%% Generated by the Erlang ASN.1 BER compiler. Version: 5.0.21 %% Purpose: Encoding and decoding of the types in ReceiptModule. -module('ReceiptModule'). -compile(nowarn_unused_vars). -dialyzer(no_improper_lists). -dialyzer(no_match). -include("ReceiptModule.hrl"). -asn1_info([{vsn,'5.0.21'}, {module,'ReceiptModule'}, {options,[{i,"src"},ber,der,noobj,{outdir,"src"},{i,"."},{i,"asn1"}]}]). -export([encoding_rule/0,maps/0,bit_string_format/0, legacy_erlang_types/0]). -export(['dialyzer-suppressions'/1]). -export([ enc_ReceiptAttribute/2, enc_Payload/2, enc_InAppAttribute/2, enc_InAppReceipt/2 ]). -export([ dec_ReceiptAttribute/2, dec_Payload/2, dec_InAppAttribute/2, dec_InAppReceipt/2 ]). -export([info/0]). -export([encode/2,decode/2]). encoding_rule() -> ber. maps() -> false. bit_string_format() -> bitstring. legacy_erlang_types() -> false. encode(Type, Data) -> try iolist_to_binary(element(1, encode_disp(Type, Data))) of Bytes -> {ok,Bytes} catch Class:Exception:Stk when Class =:= error; Class =:= exit -> case Exception of {error,{asn1,Reason}} -> {error,{asn1,{Reason,Stk}}}; Reason -> {error,{asn1,{Reason,Stk}}} end end. decode(Type, Data) -> try Result = decode_disp(Type, element(1, ber_decode_nif(Data))), {ok,Result} catch Class:Exception:Stk when Class =:= error; Class =:= exit -> case Exception of {error,{asn1,Reason}} -> {error,{asn1,{Reason,Stk}}}; Reason -> {error,{asn1,{Reason,Stk}}} end end. encode_disp('ReceiptAttribute', Data) -> enc_ReceiptAttribute(Data); encode_disp('Payload', Data) -> enc_Payload(Data); encode_disp('InAppAttribute', Data) -> enc_InAppAttribute(Data); encode_disp('InAppReceipt', Data) -> enc_InAppReceipt(Data); encode_disp(Type, _Data) -> exit({error,{asn1,{undefined_type,Type}}}). decode_disp('ReceiptAttribute', Data) -> dec_ReceiptAttribute(Data); decode_disp('Payload', Data) -> dec_Payload(Data); decode_disp('InAppAttribute', Data) -> dec_InAppAttribute(Data); decode_disp('InAppReceipt', Data) -> dec_InAppReceipt(Data); decode_disp(Type, _Data) -> exit({error,{asn1,{undefined_type,Type}}}). info() -> case ?MODULE:module_info(attributes) of Attributes when is_list(Attributes) -> case lists:keyfind(asn1_info, 1, Attributes) of {_,Info} when is_list(Info) -> Info; _ -> [] end; _ -> [] end. %%================================ %% ReceiptAttribute %%================================ enc_ReceiptAttribute(Val) -> enc_ReceiptAttribute(Val, [<<48>>]). enc_ReceiptAttribute(Val, TagIn) -> {_,Cindex1,Cindex2,Cindex3} = Val, %%------------------------------------------------- %% attribute type(1) with type INTEGER %%------------------------------------------------- {EncBytes1,EncLen1} = encode_integer(Cindex1, [<<2>>]), %%------------------------------------------------- %% attribute version(2) with type INTEGER %%------------------------------------------------- {EncBytes2,EncLen2} = encode_integer(Cindex2, [<<2>>]), %%------------------------------------------------- %% attribute value(3) with type OCTET STRING %%------------------------------------------------- {EncBytes3,EncLen3} = encode_restricted_string(Cindex3, [<<4>>]), BytesSoFar = [EncBytes1, EncBytes2, EncBytes3], LenSoFar = EncLen1 + EncLen2 + EncLen3, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_ReceiptAttribute(Tlv) -> dec_ReceiptAttribute(Tlv, [16]). dec_ReceiptAttribute(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute type(1) with type INTEGER %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = decode_integer(V1, [2]), %%------------------------------------------------- %% attribute version(2) with type INTEGER %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = decode_integer(V2, [2]), %%------------------------------------------------- %% attribute value(3) with type OCTET STRING %%------------------------------------------------- [V3|Tlv4] = Tlv3, Term3 = decode_octet_string(V3, [4]), case Tlv4 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed end, Res1 = {'ReceiptAttribute',Term1,Term2,Term3}, Res1. %%================================ %% Payload %%================================ enc_Payload(Val) -> enc_Payload(Val, [<<49>>]). enc_Payload(Val, TagIn) -> {EncBytes,EncLen} = 'enc_Payload_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_Payload_components'([], AccBytes, AccLen) -> {dynamicsort_SETOF(AccBytes),AccLen}; 'enc_Payload_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'enc_ReceiptAttribute'(H, [<<48>>]), 'enc_Payload_components'(T,[EncBytes|AccBytes], AccLen + EncLen). dec_Payload(Tlv) -> dec_Payload(Tlv, [17]). dec_Payload(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['dec_ReceiptAttribute'(V1, [16]) || V1 <- Tlv1]. %%================================ %% InAppAttribute %%================================ enc_InAppAttribute(Val) -> enc_InAppAttribute(Val, [<<48>>]). enc_InAppAttribute(Val, TagIn) -> {_,Cindex1,Cindex2,Cindex3} = Val, %%------------------------------------------------- %% attribute type(1) with type INTEGER %%------------------------------------------------- {EncBytes1,EncLen1} = encode_integer(Cindex1, [<<2>>]), %%------------------------------------------------- %% attribute version(2) with type INTEGER %%------------------------------------------------- {EncBytes2,EncLen2} = encode_integer(Cindex2, [<<2>>]), %%------------------------------------------------- %% attribute value(3) with type OCTET STRING %%------------------------------------------------- {EncBytes3,EncLen3} = encode_restricted_string(Cindex3, [<<4>>]), BytesSoFar = [EncBytes1, EncBytes2, EncBytes3], LenSoFar = EncLen1 + EncLen2 + EncLen3, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_InAppAttribute(Tlv) -> dec_InAppAttribute(Tlv, [16]). dec_InAppAttribute(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute type(1) with type INTEGER %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = decode_integer(V1, [2]), %%------------------------------------------------- %% attribute version(2) with type INTEGER %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = decode_integer(V2, [2]), %%------------------------------------------------- %% attribute value(3) with type OCTET STRING %%------------------------------------------------- [V3|Tlv4] = Tlv3, Term3 = decode_octet_string(V3, [4]), case Tlv4 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed end, Res1 = {'InAppAttribute',Term1,Term2,Term3}, Res1. %%================================ %% InAppReceipt %%================================ enc_InAppReceipt(Val) -> enc_InAppReceipt(Val, [<<49>>]). enc_InAppReceipt(Val, TagIn) -> {EncBytes,EncLen} = 'enc_InAppReceipt_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_InAppReceipt_components'([], AccBytes, AccLen) -> {dynamicsort_SETOF(AccBytes),AccLen}; 'enc_InAppReceipt_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'enc_InAppAttribute'(H, [<<48>>]), 'enc_InAppReceipt_components'(T,[EncBytes|AccBytes], AccLen + EncLen). dec_InAppReceipt(Tlv) -> dec_InAppReceipt(Tlv, [17]). dec_InAppReceipt(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['dec_InAppAttribute'(V1, [16]) || V1 <- Tlv1]. %%% %%% Run-time functions. %%% 'dialyzer-suppressions'(Arg) -> ok. ber_decode_nif(B) -> asn1rt_nif:decode_ber_tlv(B). collect_parts(TlvList) -> collect_parts(TlvList, []). collect_parts([{_, L} | Rest], Acc) when is_list(L) -> collect_parts(Rest, [collect_parts(L) | Acc]); collect_parts([{3, <>} | Rest], _Acc) -> collect_parts_bit(Rest, [Bits], Unused); collect_parts([{_T, V} | Rest], Acc) -> collect_parts(Rest, [V | Acc]); collect_parts([], Acc) -> list_to_binary(lists:reverse(Acc)). collect_parts_bit([{3, <>} | Rest], Acc, Uacc) -> collect_parts_bit(Rest, [Bits | Acc], Unused + Uacc); collect_parts_bit([], Acc, Uacc) -> list_to_binary([Uacc | lists:reverse(Acc)]). decode_integer(Tlv, TagIn) -> Bin = match_tags(Tlv, TagIn), Len = byte_size(Bin), <> = Bin, Int. decode_octet_string(Tlv, TagsIn) -> Bin = match_and_collect(Tlv, TagsIn), binary:copy(Bin). dynamicsort_SETOF(ListOfEncVal) -> BinL = lists:map(fun(L) when is_list(L) -> list_to_binary(L); (B) -> B end, ListOfEncVal), lists:sort(BinL). encode_integer(Val) -> Bytes = if Val >= 0 -> encode_integer_pos(Val, []); true -> encode_integer_neg(Val, []) end, {Bytes, length(Bytes)}. encode_integer(Val, Tag) when is_integer(Val) -> encode_tags(Tag, encode_integer(Val)); encode_integer(Val, _Tag) -> exit({error, {asn1, {encode_integer, Val}}}). encode_integer_neg(-1, [B1 | _T] = L) when B1 > 127 -> L; encode_integer_neg(N, Acc) -> encode_integer_neg(N bsr 8, [N band 255 | Acc]). encode_integer_pos(0, [B | _Acc] = L) when B < 128 -> L; encode_integer_pos(N, Acc) -> encode_integer_pos(N bsr 8, [N band 255 | Acc]). encode_length(L) when L =< 127 -> {[L], 1}; encode_length(L) -> Oct = minimum_octets(L), Len = length(Oct), if Len =< 126 -> {[128 bor Len | Oct], Len + 1}; true -> exit({error, {asn1, too_long_length_oct, Len}}) end. encode_restricted_string(OctetList, TagIn) when is_binary(OctetList) -> encode_tags(TagIn, OctetList, byte_size(OctetList)); encode_restricted_string(OctetList, TagIn) when is_list(OctetList) -> encode_tags(TagIn, OctetList, length(OctetList)). encode_tags(TagIn, {BytesSoFar, LenSoFar}) -> encode_tags(TagIn, BytesSoFar, LenSoFar). encode_tags([Tag | Trest], BytesSoFar, LenSoFar) -> {Bytes2, L2} = encode_length(LenSoFar), encode_tags(Trest, [Tag, Bytes2 | BytesSoFar], LenSoFar + byte_size(Tag) + L2); encode_tags([], BytesSoFar, LenSoFar) -> {BytesSoFar, LenSoFar}. match_and_collect(Tlv, TagsIn) -> Val = match_tags(Tlv, TagsIn), case Val of [_ | _] = PartList -> collect_parts(PartList); Bin when is_binary(Bin) -> Bin end. match_tags({T, V}, [T]) -> V; match_tags({T, V}, [T | Tt]) -> match_tags(V, Tt); match_tags([{T, V}], [T | Tt]) -> match_tags(V, Tt); match_tags([{T, _V} | _] = Vlist, [T]) -> Vlist; match_tags(Tlv, []) -> Tlv; match_tags({Tag, _V} = Tlv, [T | _Tt]) -> exit({error, {asn1, {wrong_tag, {{expected, T}, {got, Tag, Tlv}}}}}). minimum_octets(0, Acc) -> Acc; minimum_octets(Val, Acc) -> minimum_octets(Val bsr 8, [Val band 255 | Acc]). minimum_octets(Val) -> minimum_octets(Val, []).