File: error.cc

package info (click to toggle)
steghide 0.5.1-14
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 3,432 kB
  • sloc: cpp: 13,302; ansic: 6,184; sh: 3,960; makefile: 384; yacc: 316; perl: 228; sed: 16
file content (163 lines) | stat: -rw-r--r-- 3,935 bytes parent folder | download | duplicates (3)
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
/*
 * steghide 0.5.1 - a steganography program
 * Copyright (C) 1999-2003 Stefan Hetzl <shetzl@chello.at>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

#include <iostream>
#include <string>
#include <cstdio>
#include <cstdarg>

#include "BinaryIO.h"
#include "common.h"
#include "error.h"

//
// class ArgError
//
ArgError::ArgError (const char* msgfmt, ...)
	: SteghideError()
{
	va_list ap ;
	va_start (ap, msgfmt) ,
	setMessage (vcompose (msgfmt, ap)) ;
	va_end (ap) ;
}

void ArgError::printMessage () const
{
	SteghideError::printMessage() ;
	std::cerr << "steghide: " << _("type \"steghide --help\" for help.") << std::endl ;
}

//
// class BinaryInputError
//
BinaryInputError::BinaryInputError (std::string fn, FILE* s)
	: SteghideError()
{
	if (feof (s)) {
		if (fn == "") {
			setMessage(_("premature end of data from standard input.")) ;
			setType (STDIN_EOF) ;
		}
		else {
			setMessage(compose (_("premature end of file \"%s\"."), fn.c_str())) ;
			setType (FILE_EOF) ;
		}
	}
	else {
		if (fn == "") {
			setMessage(_("an error occurred while reading data from standard input.")) ;
			setType (STDIN_ERR) ;
		}
		else {
			setMessage(compose (_("an error occurred while reading data from the file \"%s\"."), fn.c_str())) ;
			setType (FILE_ERR) ;
		}
	}
}

BinaryInputError::TYPE BinaryInputError::getType (void)
{
	return type ;
}

void BinaryInputError::setType (BinaryInputError::TYPE t)
{
	type = t ;
}

//
// class BinaryOutputError
//
BinaryOutputError::BinaryOutputError (std::string fn)
	: SteghideError()
{
	if (fn == "") {
		setMessage(_("an error occurred while writing data to standard output.")) ;
		setType(STDOUT_ERR) ;
	}
	else {
		setMessage(compose (_("an error occurred while writing data to the file \"%s\"."), fn.c_str())) ;
		setType(FILE_ERR) ;
	}
}

BinaryOutputError::TYPE BinaryOutputError::getType (void)
{
	return type ;
}

void BinaryOutputError::setType (BinaryOutputError::TYPE t)
{
	type = t ;
}

//
// class UnSupFileFormat
//
UnSupFileFormat::UnSupFileFormat (BinaryIO *io)
	: SteghideError()
{
	if (io->is_std()) {
		setMessage(_("the file format of the data from standard input is not supported.")) ;
	}
	else {
		setMessage(compose (_("the file format of the file \"%s\" is not supported."), io->getName().c_str())) ;
	}
}

//
// class NotImplementedError
//
NotImplementedError::NotImplementedError (const char *msgfmt, ...)
	: SteghideError()
{
	va_list ap ;
	va_start (ap, msgfmt) ;
	setMessage (vcompose (msgfmt, ap)) ;
	va_end (ap) ;
}

void NotImplementedError::printMessage () const
{
	SteghideError::printMessage() ;
	printf (_("This feature is not (yet) available. Please let me (shetzl@chello.at) know\n"
		"that you want to use this functionality to increase the chance that this will\n"
		"be implemented in the near future. Steghide has to exit now. Sorry.\n")) ;
}

//
// class CorruptDataError
//
CorruptDataError::CorruptDataError (const char* msgfmt, ...)
	: SteghideError()
{
	va_list ap ;
	va_start (ap, msgfmt) ;
	setMessage (vcompose (msgfmt, ap)) ;
	va_end (ap) ;
}

void CorruptDataError::printMessage () const
{
	SteghideError::printMessage() ;
	printf (_("Other possible reasons for this error are that the passphrase is wrong\n"
		"or that there is no embedded data.\n")) ;
}