Skip to content

Commit

Permalink
chore: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Aug 11, 2019
1 parent f64f9e5 commit b7a0ce5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
20 changes: 20 additions & 0 deletions cryptoguess/cryptoguess.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,26 @@ type Result interface {
Rest() []byte
}

//
// recursive
//

func recursiveResults(parent Result, input []byte) []Result {
results := []Result{}
for _, childExperiment := range New(input).Experiments {
for _, childResult := range childExperiment.Results() {
results = append(
results,
&stackedResult{
parent: parent,
child: childResult,
},
)
}
}
return results
}

//
// stackedResult
//
Expand Down
12 changes: 2 additions & 10 deletions cryptoguess/guess_pem.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,8 @@ func runPEMBlock(exp Experiment) []Result {
// 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,
},
)
}
for _, childResult := range recursiveResults(result, data.Bytes) {
results = append(results, childResult)
}
results = append(results, result)
}
Expand Down

0 comments on commit b7a0ce5

Please sign in to comment.