Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
MKCLOS
Core Development Platform
corepkgv2
Commits
367ac0f6
Commit
367ac0f6
authored
5 years ago
by
Vikram Ingawale
Browse files
Options
Downloads
Plain Diff
Merge branch 'devbranch' into vi_paddingstg
parents
3c3033ce
74bcaa78
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!174
fdb: pack reorganization feature
,
!155
Devbranch into staging
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
securitymdl/securitymdl.go
+23
-0
securitymdl/securitymdl.go
securitymdl/securitymdl_test.go
+24
-0
securitymdl/securitymdl_test.go
with
47 additions
and
0 deletions
securitymdl/securitymdl.go
+
23
−
0
View file @
367ac0f6
...
...
@@ -236,3 +236,26 @@ func GetHashAndSalt(plaintext, salt string) (string, error) {
}
return
hashAndSalt
,
nil
}
// PaddingDataUsingpkcs7 - This methods is copy from https://github.com/mergermarket/go-pkcs7
func
PaddingDataUsingpkcs7
(
buf
[]
byte
,
size
int
)
([]
byte
,
error
)
{
bufLen
:=
len
(
buf
)
padLen
:=
size
-
bufLen
%
size
padded
:=
make
([]
byte
,
bufLen
+
padLen
)
copy
(
padded
,
buf
)
for
i
:=
0
;
i
<
padLen
;
i
++
{
padded
[
bufLen
+
i
]
=
byte
(
padLen
)
}
return
padded
,
nil
}
// UnpaddingDataUsingpkcs7 - his methods is copy from https://github.com/mergermarket/go-pkcs7
func
UnpaddingDataUsingpkcs7
(
padded
[]
byte
,
size
int
)
([]
byte
,
error
)
{
if
len
(
padded
)
%
size
!=
0
{
return
nil
,
errormdl
.
Wrap
(
"Padded value wasn't in correct size"
)
}
bufLen
:=
len
(
padded
)
-
int
(
padded
[
len
(
padded
)
-
1
])
buf
:=
make
([]
byte
,
bufLen
)
copy
(
buf
,
padded
[
:
bufLen
])
return
buf
,
nil
}
This diff is collapsed.
Click to expand it.
securitymdl/securitymdl_test.go
+
24
−
0
View file @
367ac0f6
...
...
@@ -232,3 +232,27 @@ func TestGetHashAndSaltError(t *testing.T) {
errormdl
.
IsTestingNegetiveCaseOn
=
false
assert
.
Error
(
t
,
err
,
"This should return error"
)
}
func
TestPaddingDataUsingpkcs7
(
t
*
testing
.
T
)
{
data
:=
[]
byte
(
"hello"
)
size
:=
16
paddingData
,
err
:=
PaddingDataUsingpkcs7
(
data
,
size
)
if
err
!=
nil
{
assert
.
Errorf
(
t
,
err
,
"padding error : "
)
}
expected
:=
[]
byte
(
"hello
\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b
"
)
assert
.
Equal
(
t
,
expected
,
paddingData
)
t
.
Logf
(
"Padding Data : %v"
,
paddingData
)
}
func
TestUnpaddingDataUsingpkcs7
(
t
*
testing
.
T
)
{
paddingdata
:=
[]
byte
{
104
,
101
,
108
,
108
,
111
,
11
,
11
,
11
,
11
,
11
,
11
,
11
,
11
,
11
,
11
,
11
}
size
:=
16
unPaddingData
,
err
:=
UnpaddingDataUsingpkcs7
(
paddingdata
,
size
)
if
err
!=
nil
{
assert
.
Errorf
(
t
,
err
,
"padding error : "
)
}
expected
:=
"hello"
assert
.
Equal
(
t
,
expected
,
string
(
unPaddingData
))
t
.
Logf
(
"Unpadding Data : %v and string is %v"
,
unPaddingData
,
string
(
unPaddingData
))
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets