File: base64.H

package info (click to toggle)
cone 0.89-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 25,628 kB
  • ctags: 14,171
  • sloc: ansic: 85,400; cpp: 82,903; sh: 11,713; makefile: 1,732; perl: 832; yacc: 291; sed: 16
file content (91 lines) | stat: -rw-r--r-- 1,608 bytes parent folder | download
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
/*
** Copyright 2002, Double Precision Inc.
**
** See COPYING for distribution information.
*/
#ifndef libmail_base64_h
#define libmail_base64_h

#include "libmail_config.h"
#include "decoder.H"

#include <string>

#include "rfc822/encode.h"

LIBMAIL_START

//
// MIME base64 decoder.
//

class decodebase64 : public decoder {

	std::string decodeBuffer;

public:
	decodebase64();
	virtual ~decodebase64();
	void decode(std::string text); // text - base64 text

private:
	virtual void decoded(std::string buffer)=0;
	// decoded contents
};

// MIME base64 encoder

class encodebase64 {

	struct libmail_encode_info encodeInfo;

	static int callback_func(const char *, size_t, void *);

public:
	encodebase64();
	virtual ~encodebase64();

	void encode(std::string text);	// text - binary data to encode
	void flush();			// Flush any buffered encoded data.
private:
	virtual void encoded(std::string buffer)=0;
};

//
// A helper object that collects the output of mail::decodebase64 into a
// single string
//

class decodebase64str : public decodebase64 {

public:
	std::string challengeStr;
	decodebase64str();
	decodebase64str(std::string);
	~decodebase64str();
	void decoded(std::string s);

	operator std::string() const { return (challengeStr); }
};

//
// A helper object that base64-encodes a single chunk of data, and returns it.
//

class encodebase64str : public encodebase64 {

public:
	std::string responseStr;

	encodebase64str();
	encodebase64str(std::string);
	~encodebase64str();

	void encoded(std::string s);

	operator std::string() const { return (responseStr); }
};

LIBMAIL_END

#endif