aboutsummaryrefslogtreecommitdiffstats
path: root/wrappers/perl-xs/Botan.xs
blob: ded129d2e9d8e530e7e2bd02753e62b4b6617895 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
#ifdef __cplusplus
extern "C" {
#endif

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#ifdef __cplusplus
}
#endif

#include <botan/asn1_obj.h>
#include <botan/asn1_oid.h>
#include <botan/base64.h>
#include <botan/basefilt.h>
#include <botan/hex.h>
#include <botan/init.h>
#include <botan/oids.h>
#include <botan/x509cert.h>
#include <botan/x509_ext.h>


/* xsubpp converts ':' to '_' in typemap. We create our types without ':' */
 
typedef Botan::ASN1_String		Botan__ASN1_String;
typedef Botan::AlgorithmIdentifier	Botan__AlgorithmIdentifier;
typedef Botan::AlternativeName		Botan__AlternativeName;
typedef Botan::Attribute		Botan__Attribute;
typedef Botan::Base64_Decoder		Botan__Base64_Decoder;
typedef Botan::Base64_Encoder		Botan__Base64_Encoder;
typedef Botan::Chain			Botan__Chain;
typedef Botan::Certificate_Extension	Botan__Extension;
typedef Botan::Filter			Botan__Filter;
typedef Botan::Fork			Botan__Fork;
typedef Botan::Hex_Decoder		Botan__Hex_Decoder;
typedef Botan::Hex_Encoder		Botan__Hex_Encoder;
typedef Botan::OID			Botan__OID;
typedef Botan::Pipe			Botan__Pipe;
typedef Botan::X509_Certificate		Botan__X509_Certificate;
typedef Botan::X509_DN			Botan__X509_DN;
typedef Botan::X509_Time		Botan__X509_Time;
typedef Botan::u32bit			Botan__u32bit;


/* Types to keep track of destruction C++ objects passed
 * into other objects...
 * An Botan object is deleted by his parent object into which is passed,
 * e.g. some Filter is deleted when his Pipe is destructed. We must
 * track this and not to delete object again in Perls destructor.
 */

class ObjectInfo
{
private:
    I32	    d_signature;
    bool    d_del;
public:
    static I32 const SIGNVAL = 0x696a626f;
    ObjectInfo() : d_signature(SIGNVAL),
		    d_del(true)		    {};
    ~ObjectInfo()			    {};
    void    set_delete(bool del = true)	    { d_del = del; };
    void    set_delete_no()		    { set_delete(false); };
    void    set_delete_yes()		    { set_delete(true); };
    bool    should_delete() const	    { return d_del; };
};

/* Constant object in initial state - template */

ObjectInfo const oi_init;


/* Botan library initializer ... */

Botan::LibraryInitializer botan_init;



/*============================================================================*/

MODULE = Botan				    PACKAGE = Botan

PROTOTYPES: ENABLE

void
constant(char *name)
    CODE:
	using namespace Botan;
	errno = 0;
	switch (name[0])
	{
	    case 'F':
	        if ( strEQ(name, "FULL_CHECK") )
		    XSRETURN_IV( FULL_CHECK );	    // Decoder_Checking enum
		break;
	    case 'I':
	        if ( strEQ(name, "IGNORE_WS") )
		    XSRETURN_IV( IGNORE_WS );	    // Decoder_Checking enum
		break;
	    case 'N':
	        if ( strEQ(name, "NONE") )
		    XSRETURN_IV( NONE );	    // Decoder_Checking enum
		break;
	}
	errno = EINVAL;
	XSRETURN_UNDEF;


# =========================== Botan::Chain ==========================

MODULE = Botan				    PACKAGE = Botan::Chain

Botan__Chain *
Botan__Chain::new(f1 = 0, f2 = 0, f3 = 0, f4 = 0)
	Botan__Filter	*f1;
	Botan__Filter	*f2;
	Botan__Filter	*f3;
	Botan__Filter	*f4;
    PREINIT:
	ObjectInfo	*f1_oi;
	ObjectInfo	*f2_oi;
	ObjectInfo	*f3_oi;
	ObjectInfo	*f4_oi;
    CODE:
	try {
	    RETVAL = new Botan__Chain(f1, f2, f3, f4);
	    if ( f1 ) f1_oi->set_delete_no();
	    if ( f2 ) f2_oi->set_delete_no();
	    if ( f3 ) f3_oi->set_delete_no();
	    if ( f4 ) f4_oi->set_delete_no();
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

void
Botan__Chain::DESTROY()
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	if ( THIS_oi->should_delete() )
	    try {
		delete THIS;
	    }
	    catch (const std::exception &e) {
		croak(e.what());
	    }


# =========================== Botan::Fork ==========================

MODULE = Botan				    PACKAGE = Botan::Fork

Botan__Fork *
Botan__Fork::new(f1 = 0, f2 = 0, f3 = 0, f4 = 0)
	Botan__Filter	*f1;
	Botan__Filter	*f2;
	Botan__Filter	*f3;
	Botan__Filter	*f4;
    PREINIT:
	ObjectInfo	*f1_oi;
	ObjectInfo	*f2_oi;
	ObjectInfo	*f3_oi;
	ObjectInfo	*f4_oi;
    CODE:
	try {
	    RETVAL = new Botan__Fork(f1, f2, f3, f4);
	    if ( f1 ) f1_oi->set_delete_no();
	    if ( f2 ) f2_oi->set_delete_no();
	    if ( f3 ) f3_oi->set_delete_no();
	    if ( f4 ) f4_oi->set_delete_no();
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

void
Botan__Fork::DESTROY()
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	if ( THIS_oi->should_delete() )
	    try {
		delete THIS;
	    }
	    catch (const std::exception &e) {
		croak(e.what());
	    }


# ============================ Botan::Base64_Decoder ============================

MODULE = Botan				    PACKAGE = Botan::Base64_Decoder

Botan__Base64_Decoder *
Botan__Base64_Decoder::new(checking = Botan::NONE)
	int	checking;
    CODE:
	try {
	    using namespace Botan;
	    RETVAL = new Base64_Decoder((Decoder_Checking)checking);
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

void
Botan__Base64_Decoder::DESTROY()
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	if ( THIS_oi->should_delete() )
	    try {
		delete THIS;
	    }
	    catch (const std::exception &e) {
		croak(e.what());
	    }


# =========================== Botan::Base64_Encoder ==========================

MODULE = Botan				    PACKAGE = Botan::Base64_Encoder

Botan__Base64_Encoder *
Botan__Base64_Encoder::new(breaks = false, length = 72)
	bool		breaks;
       	Botan__u32bit	length;
    CODE:
	try {
	    RETVAL = new Botan__Base64_Encoder(breaks, length);
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

void
Botan__Base64_Encoder::DESTROY()
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	if ( THIS_oi->should_delete() )
	    try {
		delete THIS;
	    }
	    catch (const std::exception &e) {
		croak(e.what());
	    }


# ============================ Botan::Hex_Decoder ============================

MODULE = Botan				    PACKAGE = Botan::Hex_Decoder

Botan__Hex_Decoder *
Botan__Hex_Decoder::new(checking = Botan::NONE)
	int	checking;
    CODE:
	try {
	    using namespace Botan;
	    RETVAL = new Hex_Decoder((Decoder_Checking)checking);
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

void
Botan__Hex_Decoder::DESTROY()
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	if ( THIS_oi->should_delete() )
	    try {
		delete THIS;
	    }
	    catch (const std::exception &e) {
		croak(e.what());
	    }


# ============================ Botan::Hex_Encoder ============================

MODULE = Botan				    PACKAGE = Botan::Hex_Encoder

Botan__Hex_Encoder *
Botan__Hex_Encoder::new(breaks = false, length = 72, lcase = false)
	bool		breaks;
       	Botan__u32bit	length;
	bool		lcase;
    CODE:
	try {
	    using Botan::Hex_Encoder;
	    RETVAL = new Hex_Encoder(breaks, length,
		    lcase ? Hex_Encoder::Lowercase : Hex_Encoder::Uppercase);
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

void
Botan__Hex_Encoder::DESTROY()
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	if ( THIS_oi->should_delete() )
	    try {
		delete THIS;
	    }
	    catch (const std::exception &e) {
		croak(e.what());
	    }


# ================================ Botan::OID ================================

MODULE = Botan				    PACKAGE = Botan::OID

Botan__OID *
Botan__OID::new(s)
	char *s;
    CODE:
	try {
	    RETVAL = new Botan__OID(s);
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

void
Botan__OID::DESTROY()
    CODE:
	try {
	    delete THIS;
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}

char *
Botan__OID::as_string()
    CODE:
	try {
	    RETVAL = const_cast<char *>(THIS->as_string().c_str());
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL


# ================================ Botan::OIDS ================================

MODULE = Botan				    PACKAGE = Botan::OIDS

void
add_oid(oid, name)
	Botan__OID  *oid;
       	char	    *name;
    CODE:
	try {
	    Botan::OIDS::add_oid(*oid, name);
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}

char *
lookup_by_oid(oid)
	Botan__OID *oid;
    CODE:
	try {
	    RETVAL = const_cast<char *>(Botan::OIDS::lookup(*oid).c_str());
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

Botan__OID *
lookup_by_name(name)
	char *name;
    CODE:
	try {
	    RETVAL = new Botan__OID(Botan::OIDS::lookup(name));
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
	char const * CLASS = "Botan::OID";
    OUTPUT:
	RETVAL

int
have_oid(name)
	char *name;
    CODE:
	try {
	    RETVAL = Botan::OIDS::have_oid(name);
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL


# ================================ Botan::Pipe ================================

MODULE = Botan				    PACKAGE = Botan::Pipe

Botan__Pipe *
Botan__Pipe::new(...)
    CODE:
	for (I32 i = 1; i < items; i++)
	{
	    if ( !sv_isobject(ST(i)) || (SvTYPE(SvRV(ST(i))) != SVt_PVMG) )
		croak("Botan::Pipe::new() -- arg %u is not "
			"a blessed SV reference", i +1);
	    if ( !sv_derived_from(ST(i), "Botan::Filter") )
		croak("Botan::Pipe::new() -- arg %u is not "
			"an object derived from Botan::Filter", i +1);
	    MAGIC *mg = mg_find(SvRV(ST(i)), '~');
	    if ( mg == 0
		    || mg->mg_len != sizeof(ObjectInfo)
		    || *(I32 *)(mg->mg_ptr) != ObjectInfo::SIGNVAL )
		croak("Botan::Pipe::new() -- arg %u has no "
			"valid private magic data (ObjectInfo)", i +1);
	}
	try {
	    RETVAL = new Botan__Pipe();
	    for (I32 i = 1; i < items; i++)
	    {
		SV *osv = (SV *)SvRV(ST(i));
		ObjectInfo *oi = (ObjectInfo *)(mg_find(osv, '~')->mg_ptr);
		RETVAL->append((Botan__Filter *)(SvIV(osv)));
		oi->set_delete_no();
	    }
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

void
Botan__Pipe::DESTROY()
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	try {
	    delete THIS;
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}

void
Botan__Pipe::write(s)
	SV *s;
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	STRLEN len;
	char *ptr = SvPV(s, len);
	try {
	    THIS->write((unsigned char *)ptr, len);
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}

void
Botan__Pipe::process_msg(s)
	SV *s;
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	STRLEN len;
	char *ptr = SvPV(s, len);
	try {
	    THIS->process_msg((unsigned char *)ptr, len);
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}

Botan__u32bit
Botan__Pipe::remaining(msgno = Botan::Pipe::DEFAULT_MESSAGE)
	Botan__u32bit msgno;
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	try {
	    RETVAL = THIS->remaining(msgno);
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

SV *
Botan__Pipe::read(len = 0xFFFFFFFF, msgno = Botan::Pipe::DEFAULT_MESSAGE)
	Botan__u32bit len;
	Botan__u32bit msgno;
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	try {
	    if ( len > THIS->remaining(msgno) )
		len = THIS->remaining(msgno);
	    RETVAL = NEWSV(0, len);
	    SvPOK_on(RETVAL);
	    if ( len > 0 )
		SvCUR_set(RETVAL, THIS->read((unsigned char *)SvPVX(RETVAL),
			    len, msgno));
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

SV *
Botan__Pipe::peek(len = 0xFFFFFFFF, offset = 0, \
		msgno = Botan::Pipe::DEFAULT_MESSAGE)
	Botan__u32bit len;
	Botan__u32bit offset;
	Botan__u32bit msgno;
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	try {
	    if ( len > THIS->remaining(msgno) )
		len = THIS->remaining(msgno);
	    RETVAL = NEWSV(0, len);
	    SvPOK_on(RETVAL);
	    if ( len > 0 )
		SvCUR_set(RETVAL, THIS->peek((unsigned char *)SvPVX(RETVAL),
			    len, offset, msgno));
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

Botan__u32bit
Botan__Pipe::default_msg()
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	try {
	    RETVAL = THIS->default_msg();
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

void
Botan__Pipe::set_default_msg(msgno)
	Botan__u32bit msgno;
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	try {
	    THIS->set_default_msg(msgno);
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}

Botan__u32bit
Botan__Pipe::message_count()
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	try {
	    RETVAL = THIS->message_count();
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

bool
Botan__Pipe::end_of_data()
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	try {
	    RETVAL = THIS->end_of_data();
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

void
Botan__Pipe::start_msg()
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	try {
	    THIS->start_msg();
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}

void
Botan__Pipe::end_msg()
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	try {
	    THIS->end_msg();
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}

void
Botan__Pipe::reset()
    PREINIT:
	ObjectInfo	*THIS_oi;
    CODE:
	try {
	    THIS->reset();
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}


# ========================== Botan::X509_Certificate ==========================

MODULE = Botan				    PACKAGE = Botan::X509_Certificate

Botan__X509_Certificate *
Botan__X509_Certificate::new(char *fn)
    CODE:
	try {
	    RETVAL = new Botan__X509_Certificate(fn);
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

void
Botan__X509_Certificate::DESTROY()
    CODE:
	try {
	    delete THIS;
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}

unsigned int
Botan__X509_Certificate::x509_version()
    CODE:
	try {
	    RETVAL = THIS->x509_version();
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

char *
Botan__X509_Certificate::start_time()
    CODE:
	try {
	    RETVAL = const_cast<char *>(THIS->start_time().c_str());
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

char *
Botan__X509_Certificate::end_time()
    CODE:
	try {
	    RETVAL = const_cast<char *>(THIS->end_time().c_str());
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

char *
Botan__X509_Certificate::subject_info(char *info)
    CODE:
	try {
            std::vector<std::string> s = THIS->subject_info(info);

            if(s.size() > 0)
                RETVAL = const_cast<char *>(s[0].c_str());
            else
                RETVAL = "err";
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

char *
Botan__X509_Certificate::issuer_info(char *info)
    CODE:
	try {
            std::vector<std::string> s = THIS->subject_info(info);

            if(s.size() > 0)
                RETVAL = const_cast<char *>(s[0].c_str());
            else
                RETVAL = "err";
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

Botan__X509_DN *
Botan__X509_Certificate::subject_dn()
    CODE:
	try {
	    RETVAL = new Botan__X509_DN(THIS->subject_dn());
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
	char const * CLASS = "Botan::X509_DN";
    OUTPUT:
	RETVAL

Botan__X509_DN *
Botan__X509_Certificate::issuer_dn()
    CODE:
	try {
	    RETVAL = new Botan__X509_DN(THIS->issuer_dn());
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
	char const * CLASS = "Botan::X509_DN";
    OUTPUT:
	RETVAL


# ============================== Botan::X509_DN ==============================

MODULE = Botan				    PACKAGE = Botan::X509_DN

Botan__X509_DN *
Botan__X509_DN::new()
    CODE:
	try {
	    RETVAL = new Botan__X509_DN();
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL

void
Botan__X509_DN::DESTROY()
    CODE:
	try {
	    delete THIS;
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}

AV *
Botan__X509_DN::get_attributes()
    CODE:
	try {
	    using namespace std;
	    using namespace Botan;

	    typedef multimap<OID, string>::const_iterator rdn_iter;

	    multimap<OID, string> const &atrmmap = THIS->get_attributes();
	    RETVAL = newAV();
	    for(rdn_iter i = atrmmap.begin(); i != atrmmap.end(); i++)
	    {
		string const &atr = i->first.as_string();
		string const &val = i->second;
		av_push(RETVAL, newSVpvn(atr.c_str(), atr.length()));
		av_push(RETVAL, newSVpvn(val.c_str(), val.length()));
	    }
	}
	catch (const std::exception &e) {
	    croak(e.what());
	}
    OUTPUT:
	RETVAL