Drizzled Public API Documentation

mysql_password.cc
00001 /* Copyright (C) 2010 Rackspace
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 #include <config.h>
00017 #include "mysql_password.h"
00018 #include <drizzled/algorithm/sha1.h>
00019 #include <drizzled/util/convert.h>
00020 
00021 using namespace std;
00022 
00023 namespace drizzle_plugin {
00024 
00025 const char* MySQLPasswordName = "mysql_password";
00026 
00027 const char *MySQLPassword::func_name() const
00028 {
00029   return MySQLPasswordName;
00030 }
00031   
00032 void MySQLPassword::fix_length_and_dec()
00033 {
00034   max_length= args[0]->max_length;
00035 }
00036 
00037 bool MySQLPassword::check_argument_count(int n)
00038 {
00039   return n == 1;
00040 }
00041 
00042 drizzled::String *MySQLPassword::val_str(drizzled::String *str)
00043 {
00044   uint8_t hash_tmp1[SHA1_DIGEST_LENGTH];
00045   uint8_t hash_tmp2[SHA1_DIGEST_LENGTH];
00046 
00047   drizzled::String argument;
00048   drizzled::do_sha1(*args[0]->val_str(&argument), hash_tmp1);
00049   drizzled::do_sha1(data_ref(hash_tmp1, SHA1_DIGEST_LENGTH), hash_tmp2);
00050 
00051   str->realloc(SHA1_DIGEST_LENGTH * 2);
00052   drizzled::drizzled_string_to_hex(str->ptr(), reinterpret_cast<const char*>(hash_tmp2), SHA1_DIGEST_LENGTH);
00053   str->length(SHA1_DIGEST_LENGTH * 2);
00054 
00055   return str;
00056 }
00057 
00058 } /* namespace drizzle_plugin */