blob: 26b91cab2e0c266643469effbc98ab2a1855d39d [file] [log] [blame]
Bob Badoura99ac622021-10-25 16:21:00 -07001// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package compliance
16
17import (
18 "fmt"
Bob Badoura99ac622021-10-25 16:21:00 -070019)
20
Bob Badour103eb0f2022-01-10 13:50:57 -080021// LicenseCondition identifies a recognized license condition by setting the
22// corresponding bit.
23type LicenseCondition uint16
Bob Badoura99ac622021-10-25 16:21:00 -070024
Bob Badour103eb0f2022-01-10 13:50:57 -080025// LicenseConditionMask is a bitmask for the recognized license conditions.
26const LicenseConditionMask = LicenseCondition(0x3ff)
27
28const (
29 // UnencumberedCondition identifies public domain or public domain-
30 // like license that disclaims copyright.
31 UnencumberedCondition = LicenseCondition(0x0001)
32 // PermissiveCondition identifies a license without notice or other
33 // significant requirements.
34 PermissiveCondition = LicenseCondition(0x0002)
35 // NoticeCondition identifies a typical open-source license with only
36 // notice or attribution requirements.
37 NoticeCondition = LicenseCondition(0x0004)
38 // ReciprocalCondition identifies a license with requirement to share
39 // the module's source only.
40 ReciprocalCondition = LicenseCondition(0x0008)
41 // RestrictedCondition identifies a license with requirement to share
42 // all source code linked to the module's source.
43 RestrictedCondition = LicenseCondition(0x0010)
44 // RestrictedClasspathExceptionCondition identifies RestrictedCondition
45 // waived for dynamic linking from independent modules.
46 RestrictedClasspathExceptionCondition = LicenseCondition(0x0020)
47 // WeaklyRestrictedCondition identifies a RestrictedCondition waived
48 // for dynamic linking.
49 WeaklyRestrictedCondition = LicenseCondition(0x0040)
50 // ProprietaryCondition identifies a license with source privacy
51 // requirements.
52 ProprietaryCondition = LicenseCondition(0x0080)
53 // ByExceptionOnly identifies a license where policy requires product
54 // counsel review prior to use.
55 ByExceptionOnlyCondition = LicenseCondition(0x0100)
56 // NotAllowedCondition identifies a license with onerous conditions
57 // where policy prohibits use.
58 NotAllowedCondition = LicenseCondition(0x0200)
59)
60
61var (
62 // RecognizedConditionNames maps condition strings to LicenseCondition.
63 RecognizedConditionNames = map[string]LicenseCondition{
64 "unencumbered": UnencumberedCondition,
65 "permissive": PermissiveCondition,
66 "notice": NoticeCondition,
67 "reciprocal": ReciprocalCondition,
68 "restricted": RestrictedCondition,
69 "restricted_with_classpath_exception": RestrictedClasspathExceptionCondition,
70 "restricted_allows_dynamic_linking": WeaklyRestrictedCondition,
71 "proprietary": ProprietaryCondition,
72 "by_exception_only": ByExceptionOnlyCondition,
73 "not_allowed": NotAllowedCondition,
74 }
75)
76
77// Name returns the condition string corresponding to the LicenseCondition.
Bob Badoura99ac622021-10-25 16:21:00 -070078func (lc LicenseCondition) Name() string {
Bob Badour103eb0f2022-01-10 13:50:57 -080079 switch lc {
80 case UnencumberedCondition:
81 return "unencumbered"
82 case PermissiveCondition:
83 return "permissive"
84 case NoticeCondition:
85 return "notice"
86 case ReciprocalCondition:
87 return "reciprocal"
88 case RestrictedCondition:
89 return "restricted"
90 case RestrictedClasspathExceptionCondition:
91 return "restricted_with_classpath_exception"
92 case WeaklyRestrictedCondition:
93 return "restricted_allows_dynamic_linking"
94 case ProprietaryCondition:
95 return "proprietary"
96 case ByExceptionOnlyCondition:
97 return "by_exception_only"
98 case NotAllowedCondition:
99 return "not_allowed"
Bob Badoura99ac622021-10-25 16:21:00 -0700100 }
Bob Badour103eb0f2022-01-10 13:50:57 -0800101 panic(fmt.Errorf("unrecognized license condition: %04x", lc))
Bob Badoura99ac622021-10-25 16:21:00 -0700102}