-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add two buildin function ( decode and encode) #7622
Conversation
Add two buildin function ( decode and encode): 1) add crypt.go to util/encrypt 2) modify buildin_encryption.go
Hi contributor, thanks for your PR. This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically. |
mysql> select decode("pingancap","pass1234"); +--------------------------------+ | decode("pingancap","pass1234") | +--------------------------------+ | .�[P�n��� | +--------------------------------+ 1 row in set (0.32 sec) mysql> select encode(decode("pingancap","pass1234"),"pass1234"); +---------------------------------------------------+ | encode(decode("pingancap","pass1234"),"pass1234") | +---------------------------------------------------+ | pingancap | +---------------------------------------------------+ 1 row in set (0.00 sec) mysql>
Note that these functions are deprecated in 5.7 and removed in MySQL 8.0, as the crypto is now considered weak. |
mysql> select decode("pingancap","pass1234"); +--------------------------------+ | decode("pingancap","pass1234") | +--------------------------------+ | .�[P�n��� | +--------------------------------+ 1 row in set (0.32 sec) mysql> select encode(decode("pingancap","pass1234"),"pass1234"); +---------------------------------------------------+ | encode(decode("pingancap","pass1234"),"pass1234") | +---------------------------------------------------+ | pingancap | +---------------------------------------------------+ 1 row in set (0.00 sec) mysql>
expression/builtin_encryption.go
Outdated
return "", true, errors.Trace(err) | ||
} | ||
|
||
decodeStr, _ := encrypt.SQLDecode(dataStr, passwordStr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should check the returned error
@lanjingquan Please fix CI. |
how to run ci check again after i fix it ? |
@lanjingquan when you push new code, ci will rerun automatically. You can cilck the detail link to check what is going wrong. |
Do you port the code from MySQL |
@lanjingquan You can run |
@winkyao I looked at the implementation code of MySQL and transferred them from C++ to Go to ensure that the same results could be obtained. |
util/encrypt/crypt.go
Outdated
seed1 := nr & ((uint32(1) << 31) - uint32(1)) | ||
seed2 := nr2 & ((uint32(1) << 31) - uint32(1)) | ||
|
||
fmt.Println(seed1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the debug code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done! Thanks!
@XuHuaiyu PTAL |
util/encrypt/crypt.go
Outdated
} | ||
|
||
// SQLCrypt use to store initialization results | ||
type SQLCrypt struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd better not export struct SQLCrypt
if it's not used outside module util/crypt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
isError bool | ||
}{ | ||
{"", "", "", false}, | ||
{"pingcap", "1234567890123456", "2C35B5A4ADF391", false}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
isError bool | ||
}{ | ||
{"", "", "", false}, | ||
{"pingcap", "1234567890123456", "pingcap", false}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
}{ | ||
{"", "", ""}, | ||
{"pingcap", "1234567890123456", "2C35B5A4ADF391"}, | ||
{"pingcap", "asdfjasfwefjfjkj", "351CC412605905"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some cases for NULL
inputs and other conditions, like:
mysql> select hex(decode("数据库", "asdfjasfwefjfjkj"));
+----------------------------------------------+
| hex(decode("数据库", "asdfjasfwefjfjkj")) |
+----------------------------------------------+
| 8A5F1D65A3BECDD210 |
+----------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select hex(decode(12355.5555, "asdfjasfwefjfjkj"));
+---------------------------------------------+
| hex(decode(12355.5555, "asdfjasfwefjfjkj")) |
+---------------------------------------------+
| E2359202FA4CDD5AB4F2 |
+---------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select hex(decode("分布式データベース", "asdfjasfwefjfjkj"));
+----------------------------------------------------------------+
| hex(decode("分布式データベース", "asdfjasfwefjfjkj")) |
+----------------------------------------------------------------+
| A9F2E51CEA86CC75EB4A579CA8133E9B346D5B4B610FB575637F34 |
+----------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> select hex(decode("数据库", null));
+--------------------------------+
| hex(decode("数据库", null)) |
+--------------------------------+
| NULL |
+--------------------------------+
1 row in set (0.00 sec)
mysql> select hex(decode(null, "asdfjasfwefjfjkj"));
+---------------------------------------+
| hex(decode(null, "asdfjasfwefjfjkj")) |
+---------------------------------------+
| NULL |
+---------------------------------------+
1 row in set (0.00 sec)
mysql> select hex(decode("pingcap", "密匙"));
+----------------------------------+
| hex(decode("pingcap", "密匙")) |
+----------------------------------+
| CE5C02A5010010 |
+----------------------------------+
1 row in set, 1 warning (0.01 sec)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
util/encrypt/crypt_test.go
Outdated
{"pingcap#%$%^", "*^%YTu1234567", "8634B9C55FF55E5B6328F449", false}, | ||
{"pingcap", "", "4A77B524BD2C5C", false}, | ||
{"分布式データベース","pass1234@#$%%^^&","80CADC8D328B3026D04FB285F36FED04BBCA0CC685BF78B1E687CE",false}, | ||
{"分布式データベース","分布式7782734adgwy1242","0E24CFEF272EE32B6E0BFBDB89F29FB43B4B30DAA95C3F914444BC",false}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls fix format
util/encrypt/crypt_test.go
Outdated
{"pingcap#%$%^", "*^%YTu1234567", "pingcap#%$%^", false}, | ||
{"pingcap", "", "pingcap", false}, | ||
{"分布式データベース","pass1234@#$%%^^&","分布式データベース",false}, | ||
{"分布式データベース","分布式7782734adgwy1242","分布式データベース",false}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
{"pingcap#%$%^", "*^%YTu1234567", "8634B9C55FF55E5B6328F449"}, | ||
{"pingcap", "", "4A77B524BD2C5C"}, | ||
{"分布式データベース","pass1234@#$%%^^&","80CADC8D328B3026D04FB285F36FED04BBCA0CC685BF78B1E687CE"}, | ||
{"分布式データベース","分布式7782734adgwy1242","0E24CFEF272EE32B6E0BFBDB89F29FB43B4B30DAA95C3F914444BC"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls fix fmt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot! LGTM. @zz-jason PTAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
Add two buildin function ( decode and encode):
What problem does this PR solve?
What is changed and how it works?
Check List
Tests
Code changes
Side effects
Related changes
tidb-ansible
repository