~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to lib/asn1/test/test_modified_x420.erl

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2010-03-09 17:34:57 UTC
  • mfrom: (10.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100309173457-4yd6hlcb2osfhx31
Tags: 1:13.b.4-dfsg-3
Manpages in section 1 are needed even if only arch-dependent packages are
built. So, re-enabled them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%% 
 
4
%% Copyright Ericsson AB 2008-2009. All Rights Reserved.
 
5
%% 
 
6
%% The contents of this file are subject to the Erlang Public License,
 
7
%% Version 1.1, (the "License"); you may not use this file except in
 
8
%% compliance with the License. You should have received a copy of the
 
9
%% Erlang Public License along with this software. If not, it can be
 
10
%% retrieved online at http://www.erlang.org/.
 
11
%% 
 
12
%% Software distributed under the License is distributed on an "AS IS"
 
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
%% the License for the specific language governing rights and limitations
 
15
%% under the License.
 
16
%% 
 
17
%% %CopyrightEnd%
 
18
%%
 
19
%%
 
20
-module(test_modified_x420).
 
21
 
 
22
%-compile(export_all).
 
23
-export([compile/1, test_io/1]).
 
24
 
 
25
-include("test_server.hrl").
 
26
 
 
27
compile(Config) ->
 
28
    ?line DataDir = ?config(data_dir,Config),
 
29
    ?line OutDir = ?config(priv_dir,Config),
 
30
 
 
31
    ok = asn1ct:compile(filename:join([DataDir,modified_x420,"PKCS7"]),[der,{outdir,OutDir}]),
 
32
    ok = asn1ct:compile(filename:join([DataDir,modified_x420,"InformationFramework"]),[der,{outdir,OutDir}]),
 
33
    ok = asn1ct:compile(filename:join([DataDir,modified_x420,"AuthenticationFramework"]),[der,{outdir,OutDir}]).
 
34
 
 
35
test_io(Config) ->
 
36
    io:format("~p~n~n", [catch test(Config)]).
 
37
 
 
38
test(Config) ->
 
39
    ?line DataDir = ?config(data_dir,Config),
 
40
%    ?line OutDir = ?config(priv_dir,Config),
 
41
 
 
42
    ?line Der = read_pem(filename:join([DataDir,modified_x420,"p7_signed_data.pem"])),
 
43
    ?line {ok, {_,_,SignedData}} = 'PKCS7':decode('ContentInfo', Der),
 
44
    ?line {ok,_} = 'PKCS7':decode('SignedData', SignedData).
 
45
 
 
46
read_pem(File) ->    
 
47
    ?line {ok, Bin} = file:read_file(File),
 
48
    ?line ssl_base64:join_decode(lists:flatten(extract_base64(Bin))).
 
49
 
 
50
 
 
51
 
 
52
extract_base64(Binary) ->
 
53
    extract_base64_lines(string:tokens(binary_to_list(Binary), "\n")).
 
54
 
 
55
extract_base64_lines(["-----BEGIN"++_ | Lines]) ->
 
56
    take_base64_lines(Lines, _Acc = []);
 
57
extract_base64_lines([_|Lines]) ->
 
58
    extract_base64_lines(Lines);
 
59
extract_base64_lines([]) ->
 
60
    [].
 
61
 
 
62
take_base64_lines(["-----END"++_|_], Acc) ->
 
63
    lists:reverse(Acc);
 
64
take_base64_lines([L|Lines], Acc) ->
 
65
    take_base64_lines(Lines, [L|Acc]);
 
66
take_base64_lines([], Acc) ->
 
67
    lists:reverse(Acc).