// Copyright 2023 Google LLC
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd

syntax = "proto2";

package capslock.proto;

option go_package = "github.com/google/capslock/proto";

message CapabilityInfo {
  // The name of the package.
  optional string package_name = 1;

  // Name of the capability.
  optional string capability_name = 7;

  // An enum for the capability.  New code should use capability_name instead.
  optional Capability capability = 2;

  // The dependency path to where the capability is incurred.
  optional string dep_path = 3;

  // The dependency path to where the capability is incurred.
  // Each element is a single function or method.
  repeated Function path = 6;

  // The location of the package.
  optional string package_dir = 4;

  // Classification of how the capability was incurred.
  optional CapabilityType capability_type = 5;
}

message Function {
  optional string name = 1;

  message Site {
    optional string filename = 1;
    optional int64 line = 2;
    optional int64 column = 3;
  }
  optional Site site = 2;
  optional string package = 3;
}

message ModuleInfo {
  optional string path = 1;
  optional string version = 2;
}

message PackageInfo {
  optional string path = 1;

  // ignored_files contains a list of source files in the package directory
  // that were ignored due to the build configuration and build tags.  See
  // https://pkg.go.dev/golang.org/x/tools/go/packages#Package.IgnoredFiles
  // for more information.
  repeated string ignored_files = 2;
}

message CapabilityInfoList {
  // A list of CapabilityInfo protos.
  repeated CapabilityInfo capability_info = 1;
  repeated ModuleInfo module_info = 2;
  repeated PackageInfo package_info = 3;
}

message CapabilityCountList {
  // A list of capability counts.
  map<string, int64> capability_counts = 1;
  repeated ModuleInfo module_info = 2;
}

message CapabilityStats {
  optional Capability capability = 1;
  optional string capability_name = 7;
  optional string description = 2;
  optional int64 direct_count = 3;
  optional int64 transitive_count = 4;
  repeated Function example_callpath = 5;
  optional int64 count = 6;
}

message CapabilityStatList {
  repeated CapabilityStats capability_stats = 1;
  repeated ModuleInfo module_info = 2;
}

// Next_id = 15
enum Capability {
  CAPABILITY_UNSPECIFIED = 0;
  CAPABILITY_SAFE = 1;
  CAPABILITY_FILES = 2;
  CAPABILITY_NETWORK = 3;
  CAPABILITY_RUNTIME = 4;
  CAPABILITY_READ_SYSTEM_STATE = 5;
  CAPABILITY_MODIFY_SYSTEM_STATE = 6;
  CAPABILITY_OPERATING_SYSTEM = 7;
  CAPABILITY_SYSTEM_CALLS = 8;
  CAPABILITY_ARBITRARY_EXECUTION = 9;
  CAPABILITY_CGO = 10;
  CAPABILITY_UNANALYZED = 11;
  CAPABILITY_UNSAFE_POINTER = 12;
  CAPABILITY_REFLECT = 13;
  CAPABILITY_EXEC = 14;
}

// Next_id = 3
enum CapabilityType {
  CAPABILITY_TYPE_UNSPECIFIED = 0;
  CAPABILITY_TYPE_DIRECT = 1;
  CAPABILITY_TYPE_TRANSITIVE = 2;
}


