Mercurial > hg > octave-lyh
comparison liboctave/oct-md5.cc @ 6375:5fced7a5eee8
[project @ 2007-03-01 17:23:39 by dbateman]
author | dbateman |
---|---|
date | Thu, 01 Mar 2007 17:23:40 +0000 |
parents | |
children | 65e9cf5c7718 |
comparison
equal
deleted
inserted
replaced
6374:419017274c1e | 6375:5fced7a5eee8 |
---|---|
1 /* | |
2 | |
3 Copyright (C) 2007 David Bateman | |
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 | |
9 Free Software Foundation; either version 2, or (at your option) any | |
10 later version. | |
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 | |
18 along with Octave; see the file COPYING. If not, write to the Free | |
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
20 02110-1301, USA. | |
21 | |
22 */ | |
23 | |
24 #include <string> | |
25 #include <vector> | |
26 | |
27 #ifdef HAVE_CONFIG_H | |
28 #include "config.h" | |
29 #endif | |
30 | |
31 #include "oct-md5.h" | |
32 #include "md5.h" | |
33 | |
34 std::string | |
35 oct_md5 (const std::string str) | |
36 { | |
37 md5_state_t state; | |
38 | |
39 OCTAVE_LOCAL_BUFFER (md5_byte_t, digest, 16); | |
40 md5_init (&state); | |
41 md5_append (&state, reinterpret_cast<const md5_byte_t *>(str.c_str()), | |
42 str.length()); | |
43 md5_finish (&state, digest); | |
44 | |
45 OCTAVE_LOCAL_BUFFER (char, tmp, 33); | |
46 for (octave_idx_type i = 0; i < 16; i++) | |
47 sprintf (&tmp[2*i], "%02x", digest[i]); | |
48 tmp[32] = 0; | |
49 return std::string (tmp); | |
50 } | |
51 | |
52 /* | |
53 ;;; Local Variables: *** | |
54 ;;; mode: C++ *** | |
55 ;;; End: *** | |
56 */ |