Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
689a60d6
Commit
689a60d6
authored
Sep 13, 2023
by
Joshua Gutow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove auto-detect & only use base64
parent
d6781692
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
54 deletions
+0
-54
page.go
cannon/mipsevm/page.go
+0
-20
page_test.go
cannon/mipsevm/page_test.go
+0
-34
No files found.
cannon/mipsevm/page.go
View file @
689a60d6
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"io"
"io"
"regexp"
"sync"
"sync"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
...
@@ -21,19 +20,6 @@ var zlibWriterPool = sync.Pool{
...
@@ -21,19 +20,6 @@ var zlibWriterPool = sync.Pool{
},
},
}
}
func
detectEncoding
(
data
[]
byte
)
(
string
,
error
)
{
// Regular expressions to check for base64 and hex patterns
base64Pattern
:=
"^[A-Za-z0-9+/]*={0,2}$"
hexPattern
:=
"^[0-9a-fA-F]*$"
if
regexp
.
MustCompile
(
hexPattern
)
.
MatchString
(
string
(
data
))
{
return
"hex"
,
nil
}
else
if
regexp
.
MustCompile
(
base64Pattern
)
.
MatchString
(
string
(
data
))
{
return
"base64"
,
nil
}
return
""
,
fmt
.
Errorf
(
"Unable to determine encoding for data: %s"
,
data
)
}
type
Page
[
PageSize
]
byte
type
Page
[
PageSize
]
byte
func
(
p
*
Page
)
MarshalJSON
()
([]
byte
,
error
)
{
// nosemgrep
func
(
p
*
Page
)
MarshalJSON
()
([]
byte
,
error
)
{
// nosemgrep
...
@@ -53,12 +39,6 @@ func (p *Page) MarshalJSON() ([]byte, error) { // nosemgrep
...
@@ -53,12 +39,6 @@ func (p *Page) MarshalJSON() ([]byte, error) { // nosemgrep
func
(
p
*
Page
)
UnmarshalJSON
(
dat
[]
byte
)
error
{
func
(
p
*
Page
)
UnmarshalJSON
(
dat
[]
byte
)
error
{
// Strip off the `"` characters at the start & end.
// Strip off the `"` characters at the start & end.
dat
=
dat
[
1
:
len
(
dat
)
-
1
]
dat
=
dat
[
1
:
len
(
dat
)
-
1
]
// Detect hex or bas64 encoding. legacy hex encoding is uncompressed
if
t
,
err
:=
detectEncoding
(
dat
);
err
!=
nil
{
return
err
}
else
if
t
==
"hex"
{
return
p
.
UnmarshalText
(
dat
)
}
// Decode b64 then decompress
// Decode b64 then decompress
r
,
err
:=
zlib
.
NewReader
(
base64
.
NewDecoder
(
base64
.
StdEncoding
,
bytes
.
NewReader
(
dat
)))
r
,
err
:=
zlib
.
NewReader
(
base64
.
NewDecoder
(
base64
.
StdEncoding
,
bytes
.
NewReader
(
dat
)))
if
err
!=
nil
{
if
err
!=
nil
{
...
...
cannon/mipsevm/page_test.go
View file @
689a60d6
...
@@ -47,37 +47,3 @@ func TestCachedPage(t *testing.T) {
...
@@ -47,37 +47,3 @@ func TestCachedPage(t *testing.T) {
post5
:=
p
.
MerkleRoot
()
post5
:=
p
.
MerkleRoot
()
require
.
NotEqual
(
t
,
post4
,
post5
,
"and global invalidation works regardless of changed data"
)
require
.
NotEqual
(
t
,
post4
,
post5
,
"and global invalidation works regardless of changed data"
)
}
}
func
TestDetectEncoding
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
data
[]
byte
errs
bool
t
string
}{
{
data
:
[]
byte
(
"deadbeef"
),
errs
:
false
,
t
:
"hex"
,
},
{
data
:
[]
byte
(
"c3ViamVjdAc=="
),
errs
:
false
,
t
:
"base64"
,
},
{
data
:
[]
byte
{
0x10
,
0xff
,
0xe5
},
errs
:
true
,
t
:
""
,
},
}
for
_
,
tc
:=
range
tests
{
res
,
err
:=
detectEncoding
(
tc
.
data
)
if
tc
.
errs
{
require
.
Error
(
t
,
err
)
}
else
{
require
.
Equal
(
t
,
tc
.
t
,
res
)
require
.
NoError
(
t
,
err
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment