8000 feat: add recursive by moul · Pull Request #2 · moul/cryptoguess · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add recursive #2

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

Merged
merged 1 commit into from
Aug 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions cryptoguess/cryptoguess.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,55 @@ type Result interface {
Rest() []byte
}

//
// stackedResult
//

type stackedResult struct {
parent Result
child Result
}

func (res stackedResult) Confidence() float64 {
confidence := res.child.Confidence() * 1.1
if confidence > 1 {
return 1
}
return confidence
}

func (res stackedResult) Rest() []byte {
return res.child.Rest()
}

func (res stackedResult) Name() string {
return fmt.Sprintf("%s: %s", res.parent.Name(), res.child.Name())
}

func (res stackedResult) Err() error {
return res.child.Err()
}

func (res stackedResult) String() string {
return fmt.Sprintf("parent: %s\nchild: %s", res.parent.String(), res.child.String())
}

func (res stackedResult) Short() string {
if res.Err() == nil {
return res.Name()
}
return ""
}

func (res stackedResult) Data() interface{} {
// FIXME: aggregate data!?
return res.child.Data()
}

//
// baseResult
//

type baseResult struct {
exp Experiment
name string
Expand Down
26 changes: 20 additions & 6 deletions cryptoguess/guess_pem.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,27 @@ type PEMBlock struct{ *baseExperiment }

func runPEMBlock(exp Experiment) []Result {
results := []Result{}
result := &baseResult{exp: exp}
result.data, result.rest = pem.Decode(exp.Input())
if result.data == nil {
result.err = fmt.Errorf("no PEM data found")
data, rest := pem.Decode(exp.Input())
if data == nil {
result := &baseResult{exp: exp, rest: rest, err: fmt.Errorf("no PEM data found")}
results = append(results, result)
} else {
// FIXME: data.Type
// FIXME: data.Headers
result := &baseResult{exp: exp, rest: rest, data: data}
for _, childExperiment := range New(data.Bytes).Experiments {
for _, childResult := range childExperiment.Results() {
results = append(
results,
&stackedResult{
parent: result,
child: childResult,
},
)
}
}
results = append(results, result)
}
results = append(results, result)
// FIXME: recursively call other parsers with prefix=pem-encoded (like multiaddr)
return results
}

Expand Down
0