blob: 2aac78c870181cfa3f303efbf2e97ddf6a268ea2 [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.
Bob Badour10f5c482022-09-20 21:44:17 -070026const LicenseConditionMask = LicenseCondition(0x1ff)
Bob Badour103eb0f2022-01-10 13:50:57 -080027
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)
Bob Badour103eb0f2022-01-10 13:50:57 -080044 // WeaklyRestrictedCondition identifies a RestrictedCondition waived
45 // for dynamic linking.
Bob Badour10f5c482022-09-20 21:44:17 -070046 WeaklyRestrictedCondition = LicenseCondition(0x0020)
Bob Badour103eb0f2022-01-10 13:50:57 -080047 // ProprietaryCondition identifies a license with source privacy
48 // requirements.
Bob Badour10f5c482022-09-20 21:44:17 -070049 ProprietaryCondition = LicenseCondition(0x0040)
Bob Badour103eb0f2022-01-10 13:50:57 -080050 // ByExceptionOnly identifies a license where policy requires product
51 // counsel review prior to use.
Bob Badour10f5c482022-09-20 21:44:17 -070052 ByExceptionOnlyCondition = LicenseCondition(0x0080)
Bob Badour103eb0f2022-01-10 13:50:57 -080053 // NotAllowedCondition identifies a license with onerous conditions
54 // where policy prohibits use.
Bob Badour10f5c482022-09-20 21:44:17 -070055 NotAllowedCondition = LicenseCondition(0x0100)
Bob Badour103eb0f2022-01-10 13:50:57 -080056)
57
58var (
59 // RecognizedConditionNames maps condition strings to LicenseCondition.
60 RecognizedConditionNames = map[string]LicenseCondition{
Bob Badourcac8a3c2022-11-22 12:04:10 -080061 "unencumbered": UnencumberedCondition,
62 "permissive": PermissiveCondition,
63 "notice": NoticeCondition,
64 "reciprocal": ReciprocalCondition,
65 "restricted": RestrictedCondition,
66 "restricted_if_statically_linked": WeaklyRestrictedCondition,
67 "proprietary": ProprietaryCondition,
68 "by_exception_only": ByExceptionOnlyCondition,
69 "not_allowed": NotAllowedCondition,
Bob Badour103eb0f2022-01-10 13:50:57 -080070 }
71)
72
73// Name returns the condition string corresponding to the LicenseCondition.
Bob Badoura99ac622021-10-25 16:21:00 -070074func (lc LicenseCondition) Name() string {
Bob Badour103eb0f2022-01-10 13:50:57 -080075 switch lc {
76 case UnencumberedCondition:
77 return "unencumbered"
78 case PermissiveCondition:
79 return "permissive"
80 case NoticeCondition:
81 return "notice"
82 case ReciprocalCondition:
83 return "reciprocal"
84 case RestrictedCondition:
85 return "restricted"
Bob Badour103eb0f2022-01-10 13:50:57 -080086 case WeaklyRestrictedCondition:
Bob Badourcac8a3c2022-11-22 12:04:10 -080087 return "restricted_if_statically_linked"
Bob Badour103eb0f2022-01-10 13:50:57 -080088 case ProprietaryCondition:
89 return "proprietary"
90 case ByExceptionOnlyCondition:
91 return "by_exception_only"
92 case NotAllowedCondition:
93 return "not_allowed"
Bob Badoura99ac622021-10-25 16:21:00 -070094 }
Bob Badour10f5c482022-09-20 21:44:17 -070095 panic(fmt.Errorf("unrecognized license condition: %#v", lc))
Bob Badoura99ac622021-10-25 16:21:00 -070096}