00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00026 const char* MySQLPasswordName = "mysql_password";
00027
00028 MySQLPassword::MySQLPassword(void):
00029 Item_str_func()
00030 { }
00031
00032 const char *MySQLPassword::func_name() const
00033 {
00034 return MySQLPasswordName;
00035 }
00036
00037 void MySQLPassword::fix_length_and_dec()
00038 {
00039 max_length= args[0]->max_length;
00040 }
00041
00042 bool MySQLPassword::check_argument_count(int n)
00043 {
00044 return (n == 1);
00045 }
00046
00047 drizzled::String *MySQLPassword::val_str(drizzled::String *str)
00048 {
00049 drizzled::String argument;
00050 drizzled::String *password= args[0]->val_str(&argument);
00051 drizzled::SHA1_CTX ctx;
00052 uint8_t hash_tmp1[SHA1_DIGEST_LENGTH];
00053 uint8_t hash_tmp2[SHA1_DIGEST_LENGTH];
00054
00055 drizzled::SHA1Init(&ctx);
00056 drizzled::SHA1Update(&ctx, reinterpret_cast<uint8_t *>(password->ptr()),
00057 password->length());
00058 drizzled::SHA1Final(hash_tmp1, &ctx);
00059
00060 drizzled::SHA1Init(&ctx);
00061 drizzled::SHA1Update(&ctx, hash_tmp1, SHA1_DIGEST_LENGTH);
00062 drizzled::SHA1Final(hash_tmp2, &ctx);
00063
00064 str->realloc(SHA1_DIGEST_LENGTH * 2);
00065 drizzled::drizzled_string_to_hex(str->ptr(),
00066 reinterpret_cast<const char*>(hash_tmp2),
00067 SHA1_DIGEST_LENGTH);
00068 str->length(SHA1_DIGEST_LENGTH * 2);
00069
00070 return str;
00071 }
00072
00073 }