Mercurial > hg > octave-nkf
annotate liboctave/util/oct-md5.cc @ 20827:e54ecb33727e
lo-array-gripes.cc: Remove FIXME's related to buffer size.
* lo-array-gripes.cc: Remove FIXME's related to buffer size. Shorten sprintf
buffers from 100 to 64 characters (still well more than 19 required).
Use 'const' decorator on constant value for clarity. Remove extra space
between variable and array bracket.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 12 Oct 2015 21:13:47 -0700 |
parents | 4197fc428c7d |
children |
rev | line source |
---|---|
6375 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
3 Copyright (C) 2007-2015 David Bateman |
6375 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
6375 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
6375 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
15268
307912900544
Use angle brackets for #include <config.h> for consistency.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
24 #include <config.h> |
6375 | 25 #endif |
26 | |
8521 | 27 #include <cstdio> |
28 | |
29 #include <string> | |
30 #include <vector> | |
31 | |
6383 | 32 #include "lo-error.h" |
6375 | 33 #include "oct-md5.h" |
34 #include "md5.h" | |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
35 |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
36 static std::string |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
37 oct_md5_result_to_str (const unsigned char *buf) |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
38 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
39 char tmp[33]; |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
40 |
11293
202bd0f1863d
oct_md5_result_to_str: avoid buffer overrun; replace loop with single call to sprintf
John W. Eaton <jwe@octave.org>
parents:
11292
diff
changeset
|
41 sprintf (tmp, |
202bd0f1863d
oct_md5_result_to_str: avoid buffer overrun; replace loop with single call to sprintf
John W. Eaton <jwe@octave.org>
parents:
11292
diff
changeset
|
42 "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", |
202bd0f1863d
oct_md5_result_to_str: avoid buffer overrun; replace loop with single call to sprintf
John W. Eaton <jwe@octave.org>
parents:
11292
diff
changeset
|
43 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], |
202bd0f1863d
oct_md5_result_to_str: avoid buffer overrun; replace loop with single call to sprintf
John W. Eaton <jwe@octave.org>
parents:
11292
diff
changeset
|
44 buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], |
202bd0f1863d
oct_md5_result_to_str: avoid buffer overrun; replace loop with single call to sprintf
John W. Eaton <jwe@octave.org>
parents:
11292
diff
changeset
|
45 buf[15]); |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
46 |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
47 return std::string (tmp, 32); |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
48 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
49 |
6375 | 50 std::string |
51 oct_md5 (const std::string str) | |
52 { | |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
53 unsigned char buf[16]; |
6375 | 54 |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
55 md5_buffer (str.data (), str.length (), buf); |
6375 | 56 |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
57 return oct_md5_result_to_str (buf); |
6375 | 58 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
59 |
6383 | 60 std::string |
61 oct_md5_file (const std::string file) | |
62 { | |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
63 std::string retval; |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
64 |
14153 | 65 FILE *ifile = gnulib::fopen (file.c_str (), "rb"); |
6383 | 66 |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
67 if (ifile) |
6383 | 68 { |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
69 unsigned char buf[16]; |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
70 |
11292
231e6d1b57d6
oct_md5_file: close file after reading
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
71 int errflag = md5_stream (ifile, buf); |
231e6d1b57d6
oct_md5_file: close file after reading
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
72 |
11450
5eb10763069f
substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents:
11293
diff
changeset
|
73 gnulib::fclose (ifile); |
11292
231e6d1b57d6
oct_md5_file: close file after reading
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
74 |
231e6d1b57d6
oct_md5_file: close file after reading
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
75 if (! errflag) |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
76 retval = oct_md5_result_to_str (buf); |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
77 else |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
78 (*current_liboctave_error_handler) ("internal error in md5_stream"); |
6383 | 79 } |
80 else | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14153
diff
changeset
|
81 (*current_liboctave_error_handler) ("unable to open file '%s' for reading", |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14153
diff
changeset
|
82 file.c_str ()); |
6383 | 83 |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
84 return retval; |
6383 | 85 } |