github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/identity/signature.go (about) 1 /* 2 * Copyright (C) 2017 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package identity 19 20 import ( 21 "bytes" 22 "encoding/base64" 23 "encoding/hex" 24 ) 25 26 // SignatureBytes constructs Signature structure instance from bytes 27 func SignatureBytes(signatureBytes []byte) Signature { 28 return Signature{signatureBytes} 29 } 30 31 // SignatureHex returns Signature struct from hex string 32 func SignatureHex(signature string) Signature { 33 signatureBytes, _ := hex.DecodeString(signature) 34 return Signature{signatureBytes} 35 } 36 37 // SignatureBase64 decodes base64 string signature into Signature 38 func SignatureBase64(signature string) Signature { 39 signatureBytes, _ := base64.StdEncoding.DecodeString(signature) 40 return Signature{signatureBytes} 41 } 42 43 // Signature structure 44 type Signature struct { 45 raw []byte 46 } 47 48 // Base64 encodes signature into Base64 format 49 func (signature *Signature) Base64() string { 50 return base64.StdEncoding.EncodeToString(signature.Bytes()) 51 } 52 53 // Bytes returns signature in raw bytes format 54 func (signature *Signature) Bytes() []byte { 55 return signature.raw 56 } 57 58 // EqualsTo compares current signature with a given one 59 func (signature Signature) EqualsTo(other Signature) bool { 60 return bytes.Equal(signature.raw, other.raw) 61 }