Skip to content

Commit

Permalink
try to fix version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Feb 18, 2022
1 parent 25abc6e commit 4339ec0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
11 changes: 6 additions & 5 deletions converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"github.com/biscuit-auth/biscuit-go/datalog"
"github.com/biscuit-auth/biscuit-go/pb"
//"github.com/biscuit-auth/biscuit-go/sig"
"google.golang.org/protobuf/proto"
)

func tokenBlockToProtoBlock(input *Block) (*pb.Block, error) {
out := &pb.Block{
Symbols: *input.symbols,
Context: &input.context,
Version: &input.version,
Version: proto.Uint32(input.version),
}

out.FactsV2 = make([]*pb.FactV2, len(*input.facts))
Expand Down Expand Up @@ -52,15 +53,15 @@ func protoBlockToTokenBlock(input *pb.Block) (*Block, error) {
var rules []datalog.Rule
var checks []datalog.Check

if *input.Version > MaxSchemaVersion {
if input.GetVersion() > MaxSchemaVersion {
return nil, fmt.Errorf(
"biscuit: failed to convert proto block to token block: block version: %d > library version %d",
input.Version,
input.GetVersion(),
MaxSchemaVersion,
)
}

switch *input.Version {
switch input.GetVersion() {
case 2:
facts = make(datalog.FactSet, len(input.FactsV2))
rules = make([]datalog.Rule, len(input.RulesV2))
Expand Down Expand Up @@ -99,7 +100,7 @@ func protoBlockToTokenBlock(input *pb.Block) (*Block, error) {
rules: rules,
checks: checks,
context: *input.Context,
version: *input.Version,
version: input.GetVersion(),
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
SymbolAmbient = Symbol("ambient")
)

const MaxSchemaVersion uint32 = 1
const MaxSchemaVersion uint32 = 2

// defaultSymbolTable predefines some symbols available in every implementation, to avoid
// transmitting them with every token
Expand Down
13 changes: 8 additions & 5 deletions verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (v *verifier) LoadPolicies(verifierPolicies []byte) error {
return fmt.Errorf("verifier: failed to load policies: %w", err)
}

switch pbPolicies.Version {
switch *pbPolicies.Version {
case 1:
return v.loadPoliciesV1(pbPolicies)
default:
Expand Down Expand Up @@ -241,7 +241,7 @@ func (v *verifier) loadPoliciesV1(pbPolicies *pb.VerifierPolicies) error {
v.policies = make([]Policy, len(pbPolicies.Policies))
for i, pbPolicy := range pbPolicies.Policies {
policy := Policy{}
switch pbPolicy.Kind {
switch *pbPolicy.Kind {
case pb.Policy_Allow:
policy.Kind = PolicyKindAllow
case pb.Policy_Deny:
Expand Down Expand Up @@ -306,9 +306,11 @@ func (v *verifier) SerializePolicies() ([]byte, error) {
protoPolicy := &pb.Policy{}
switch policy.Kind {
case PolicyKindAllow:
protoPolicy.Kind = pb.Policy_Allow
kind := pb.Policy_Allow
protoPolicy.Kind = &kind
case PolicyKindDeny:
protoPolicy.Kind = pb.Policy_Deny
kind := pb.Policy_Deny
protoPolicy.Kind = &kind
default:
return nil, fmt.Errorf("verifier: unsupported policy kind %v", policy.Kind)
}
Expand All @@ -325,9 +327,10 @@ func (v *verifier) SerializePolicies() ([]byte, error) {
protoPolicies[i] = protoPolicy
}

version:= MaxSchemaVersion
return proto.Marshal(&pb.VerifierPolicies{
Symbols: *v.symbols.Clone(),
Version: MaxSchemaVersion,
Version: &version,
Facts: protoFacts,
Rules: protoRules,
Checks: protoChecks,
Expand Down

0 comments on commit 4339ec0

Please sign in to comment.