Mercurial > hg > octave-nkf
annotate liboctave/oct-md5.cc @ 10405:cc69a17ec801
remove integer math warnings
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 09 Mar 2010 08:06:30 +0100 |
parents | 07ebe522dac2 |
children | 231e6d1b57d6 |
rev | line source |
---|---|
6375 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2007, 2008, 2009 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 | |
24 #include "config.h" | |
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 { |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
39 char tmp [32]; |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
40 |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
41 for (octave_idx_type i = 0; i < 16; i++) |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
42 sprintf (&tmp[2*i], "%02x", buf[i]); |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
43 |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
44 return std::string (tmp, 32); |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
45 } |
6375 | 46 |
47 std::string | |
48 oct_md5 (const std::string str) | |
49 { | |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
50 unsigned char buf[16]; |
6375 | 51 |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
52 md5_buffer (str.data (), str.length (), buf); |
6375 | 53 |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
54 return oct_md5_result_to_str (buf); |
6375 | 55 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
56 |
6383 | 57 std::string |
58 oct_md5_file (const std::string file) | |
59 { | |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
60 std::string retval; |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
61 |
6383 | 62 FILE *ifile = fopen (file.c_str (), "rb"); |
63 | |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
64 if (ifile) |
6383 | 65 { |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
66 unsigned char buf[16]; |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
67 |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
68 if (! md5_stream (ifile, buf)) |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
69 retval = oct_md5_result_to_str (buf); |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
70 else |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
71 (*current_liboctave_error_handler) ("internal error in md5_stream"); |
6383 | 72 } |
73 else | |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
74 (*current_liboctave_error_handler) ("unable to open file `%s' for reading", |
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
75 file.c_str()); |
6383 | 76 |
10025
acd5e9df38f8
use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
77 return retval; |
6383 | 78 } |