github.com/google/osv-scalibr@v0.4.1/common/windows/registry/registry.go (about) 1 // Copyright 2025 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 15 // Package registry provides an interface to abstract the Windows registry libraries away. 16 // This allows providing more functionalities to registry libraries and also provide a better means 17 // of testing. 18 package registry 19 20 // Opener is an interface to be able to open an actual registry. 21 // It was implemented as a way to delay the time between configuring and closing/using the registry. 22 type Opener interface { 23 Open() (Registry, error) 24 } 25 26 // Registry represents an open registry hive. 27 type Registry interface { 28 // OpenKey returns a Key for the given path in a specific hive. 29 OpenKey(hive string, path string) (Key, error) 30 31 // Close closes the registry hive. 32 Close() error 33 } 34 35 // Key represents a specific registry key. 36 type Key interface { 37 // Name returns the name of the key. 38 Name() string 39 40 // Close closes the key. 41 Close() error 42 43 // ClassName returns the name of the class for the key. 44 ClassName() ([]byte, error) 45 46 // Subkeys returns the opened subkeys of the key. 47 Subkeys() ([]Key, error) 48 49 // SubkeyNames returns the names of the subkeys of the key. 50 SubkeyNames() ([]string, error) 51 52 // Value returns the value with the given name. 53 Value(name string) (Value, error) 54 55 // ValueBytes directly returns the content (as bytes) of the named value. 56 ValueBytes(name string) ([]byte, error) 57 58 // ValueString directly returns the content (as string) of the named value. 59 ValueString(name string) (string, error) 60 61 // Values returns the different values of the key. 62 Values() ([]Value, error) 63 } 64 65 // Value represents a value inside a specific key. 66 type Value interface { 67 // Name returns the name of the value. 68 Name() string 69 70 // Data returns the data of the value. 71 Data() ([]byte, error) 72 73 // DataString returns the data of the value as a string. 74 DataString() (string, error) 75 }