-
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift click to select a range
b1b66b7
Add two buildin function ( decode and encode)
lanjingquan 6406474
Add two buildin function ( decode and encode)
lanjingquan be1cdec
add two buildin function ( decode and encode)
lanjingquan 93f593a
Merge branch 'master' into lanjingquan/tidb
lanjingquan 4e4459a
fix ci
lanjingquan 4356579
Merge branch 'lanjingquan/tidb' of https://github.com/lanjingquan/tid…
lanjingquan bdf038b
fix make error
lanjingquan 0a20e3b
fix again
lanjingquan a1af035
add comment to functions
lanjingquan 86ff091
add comment again
lanjingquan c3c5de5
Merge branch 'master' into lanjingquan/tidb
lanjingquan 5c71833
remove debug code, and rename SQLCrypt struct
lanjingquan b69fb8d
Merge branch 'lanjingquan/tidb' of https://github.com/lanjingquan/tid…
lanjingquan 761a352
add some cases for NULL inputs and other conditions
lanjingquan 6f2fa41
Merge branch 'master' into lanjingquan/tidb
lanjingquan f9f7c97
fix err
lanjingquan 304ab49
Merge branch 'lanjingquan/tidb' of https://github.com/lanjingquan/tid…
lanjingquan 9e8b06f
fix err again
lanjingquan d77eec7
fix fmt
lanjingquan 70a2ce9
Merge branch 'master' into lanjingquan/tidb
zz-jason File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add comment to functions
- Loading branch information
commit a1af03548fb9b77cb4d001b7845f77375919128d
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 24,9 @@ type randStruct struct { | |
maxValueDbl float64 | ||
} | ||
|
||
// randomInit random generation structure initialization | ||
func (rs *randStruct) randomInit(password []byte, length int) { | ||
// hash password | ||
// Generate binary hash from raw text string | ||
var nr, add, nr2, tmp uint32 | ||
nr = 1345345333 | ||
add = 7 | ||
|
@@ -48,7 49,7 @@ func (rs *randStruct) randomInit(password []byte, length int) { | |
fmt.Println(seed1) | ||
fmt.Println(seed2) | ||
|
||
// init rand struct | ||
// New (MySQL 3.21 ) random generation structure initialization | ||
rs.maxValue = 0x3FFFFFFF | ||
rs.maxValueDbl = float64(rs.maxValue) | ||
rs.seed1 = seed1 % rs.maxValue | ||
|
@@ -62,7 63,7 @@ func (rs *randStruct) myRand() float64 { | |
return ((float64(rs.seed1)) / rs.maxValueDbl) | ||
} | ||
|
||
type SqlCrypt struct { | ||
type SQLCrypt struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'd better not export struct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
rand randStruct | ||
orgRand randStruct | ||
|
||
|
@@ -71,7 72,7 @@ type SqlCrypt struct { | |
shift uint32 | ||
} | ||
|
||
func (sc *SqlCrypt) init(password []byte, length int) { | ||
func (sc *SQLCrypt) init(password []byte, length int) { | ||
sc.rand.randomInit(password, length) | ||
|
||
for i := 0; i <= 255; i { | ||
|
@@ -93,12 94,12 @@ func (sc *SqlCrypt) init(password []byte, length int) { | |
sc.shift = 0 | ||
} | ||
|
||
func (sc *SqlCrypt) reinit() { | ||
func (sc *SQLCrypt) reinit() { | ||
sc.shift = 0 | ||
sc.rand = sc.orgRand | ||
} | ||
|
||
func (sc *SqlCrypt) encode(str []byte, length int) { | ||
func (sc *SQLCrypt) encode(str []byte, length int) { | ||
for i := 0; i < length; i { | ||
sc.shift ^= uint32(sc.rand.myRand() * 255.0) | ||
idx := uint32(str[i]) | ||
|
@@ -107,7 108,7 @@ func (sc *SqlCrypt) encode(str []byte, length int) { | |
} | ||
} | ||
|
||
func (sc *SqlCrypt) decode(str []byte, length int) { | ||
func (sc *SQLCrypt) decode(str []byte, length int) { | ||
for i := 0; i < length; i { | ||
sc.shift ^= uint32(sc.rand.myRand() * 255.0) | ||
idx := uint32(str[i] ^ byte(sc.shift)) | ||
|
@@ -116,8 117,9 @@ func (sc *SqlCrypt) decode(str []byte, length int) { | |
} | ||
} | ||
|
||
//SQLDecode Function to handle the decode() function | ||
func SQLDecode(str string, password string) (string, error) { | ||
var sqlCrypt SqlCrypt | ||
var sqlCrypt SQLCrypt | ||
|
||
strByte := []byte(str) | ||
passwdByte := []byte(password) | ||
|
@@ -128,8 130,9 @@ func SQLDecode(str string, password string) (string, error) { | |
return string(strByte), nil | ||
} | ||
|
||
// SQLEncode Function to handle the encode() function | ||
func SQLEncode(cryptStr string, password string) (string, error) { | ||
var sqlCrypt SqlCrypt | ||
var sqlCrypt SQLCrypt | ||
|
||
cryptStrByte := []byte(cryptStr) | ||
passwdByte := []byte(password) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!