2014-08-25 19:18:34 +09:00
|
|
|
/*
|
2014-05-06 14:23:05 +00:00
|
|
|
* s3fs - FUSE-based file system backed by Amazon S3
|
|
|
|
*
|
2017-05-07 11:24:17 +00:00
|
|
|
* Copyright(C) 2007 Randy Rizun <rrizun@gmail.com>
|
2014-05-06 14:23:05 +00:00
|
|
|
*
|
|
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2019-07-12 03:33:53 -07:00
|
|
|
#include <climits>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
2014-05-06 14:23:05 +00:00
|
|
|
#include <string>
|
|
|
|
|
2020-08-22 12:40:53 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "s3fs.h"
|
2014-05-06 14:23:05 +00:00
|
|
|
#include "s3fs_auth.h"
|
2015-08-19 11:22:30 -07:00
|
|
|
#include "string_util.h"
|
2014-05-06 14:23:05 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Utility Function
|
|
|
|
//-------------------------------------------------------------------
|
2020-09-11 18:37:24 +09:00
|
|
|
std::string s3fs_get_content_md5(int fd)
|
2014-05-06 14:23:05 +00:00
|
|
|
{
|
2020-09-14 19:00:09 +09:00
|
|
|
unsigned char* md5;
|
2020-08-22 12:40:53 +00:00
|
|
|
char* base64;
|
2020-09-11 18:37:24 +09:00
|
|
|
std::string Signature;
|
2020-08-22 12:40:53 +00:00
|
|
|
|
2020-09-14 19:00:09 +09:00
|
|
|
if(NULL == (md5 = s3fs_md5_fd(fd, 0, -1))){
|
2020-09-11 18:37:24 +09:00
|
|
|
return std::string("");
|
2020-08-22 12:40:53 +00:00
|
|
|
}
|
2020-09-14 19:00:09 +09:00
|
|
|
if(NULL == (base64 = s3fs_base64(md5, get_md5_digest_length()))){
|
|
|
|
delete[] md5;
|
2020-09-11 18:37:24 +09:00
|
|
|
return std::string(""); // ENOMEM
|
2020-08-22 12:40:53 +00:00
|
|
|
}
|
2020-09-14 19:00:09 +09:00
|
|
|
delete[] md5;
|
2020-08-22 12:40:53 +00:00
|
|
|
|
|
|
|
Signature = base64;
|
|
|
|
delete[] base64;
|
|
|
|
|
|
|
|
return Signature;
|
2014-05-06 14:23:05 +00:00
|
|
|
}
|
|
|
|
|
2020-09-14 19:00:09 +09:00
|
|
|
std::string s3fs_sha256_hex_fd(int fd, off_t start, off_t size)
|
2015-01-20 16:31:36 +00:00
|
|
|
{
|
2020-08-22 12:40:53 +00:00
|
|
|
size_t digestlen = get_sha256_digest_length();
|
2020-09-14 19:00:09 +09:00
|
|
|
unsigned char* sha256;
|
2015-01-20 16:31:36 +00:00
|
|
|
|
2020-09-14 19:00:09 +09:00
|
|
|
if(NULL == (sha256 = s3fs_sha256_fd(fd, start, size))){
|
2020-09-11 18:37:24 +09:00
|
|
|
return std::string("");
|
2020-08-22 12:40:53 +00:00
|
|
|
}
|
2015-01-20 16:31:36 +00:00
|
|
|
|
2020-09-14 19:00:09 +09:00
|
|
|
std::string sha256hex = s3fs_hex(sha256, digestlen);
|
|
|
|
delete[] sha256;
|
2015-01-20 16:31:36 +00:00
|
|
|
|
2020-09-14 19:00:09 +09:00
|
|
|
return sha256hex;
|
2015-01-20 16:31:36 +00:00
|
|
|
}
|
|
|
|
|
2014-09-07 15:08:27 +00:00
|
|
|
/*
|
|
|
|
* Local variables:
|
2020-08-22 12:40:53 +00:00
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
2014-09-07 15:08:27 +00:00
|
|
|
* End:
|
2020-08-22 12:40:53 +00:00
|
|
|
* vim600: expandtab sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: expandtab sw=4 ts=4
|
2014-09-07 15:08:27 +00:00
|
|
|
*/
|