annotate liboctave/oct-md5.cc @ 10843:229675bb7647 ss-3-3-52

version is now 3.3.52
author John W. Eaton <jwe@octave.org>
date Sun, 01 Aug 2010 11:49:45 -0400
parents 07ebe522dac2
children 231e6d1b57d6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6375
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
1 /*
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
2
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8521
diff changeset
3 Copyright (C) 2007, 2008, 2009 David Bateman
6375
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
4
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
5 This file is part of Octave.
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
6
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6383
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6383
diff changeset
10 option) any later version.
6375
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
11
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
15 for more details.
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
16
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6383
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6383
diff changeset
19 <http://www.gnu.org/licenses/>.
6375
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
20
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
21 */
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
22
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
24 #include "config.h"
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
25 #endif
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
26
8521
93cf10950334 tmpdir=tmpnam;
Rafael Laboissiere <rafael@debian.org>
parents: 8377
diff changeset
27 #include <cstdio>
93cf10950334 tmpdir=tmpnam;
Rafael Laboissiere <rafael@debian.org>
parents: 8377
diff changeset
28
93cf10950334 tmpdir=tmpnam;
Rafael Laboissiere <rafael@debian.org>
parents: 8377
diff changeset
29 #include <string>
93cf10950334 tmpdir=tmpnam;
Rafael Laboissiere <rafael@debian.org>
parents: 8377
diff changeset
30 #include <vector>
93cf10950334 tmpdir=tmpnam;
Rafael Laboissiere <rafael@debian.org>
parents: 8377
diff changeset
31
6383
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
32 #include "lo-error.h"
6375
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
33 #include "oct-md5.h"
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
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
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
46
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
47 std::string
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
48 oct_md5 (const std::string str)
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
49 {
10025
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
50 unsigned char buf[16];
6375
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
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
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
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
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
55 }
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
56
6383
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
57 std::string
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
58 oct_md5_file (const std::string file)
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
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
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
62 FILE *ifile = fopen (file.c_str (), "rb");
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
63
10025
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
64 if (ifile)
6383
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
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
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
72 }
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
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
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
76
10025
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
77 return retval;
6383
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
78 }