From 465f54e4667d1a383c20a3ea459ae1e051d60ca9 Mon Sep 17 00:00:00 2001 From: Mathis Maquenne <124215603+mathismqn@users.noreply.github.com> Date: Wed, 29 Jul 2026 11:21:03 +0200 Subject: [PATCH] refactor: disambiguate blowfish crypto helper names --- internal/crypto/blowfish.go | 16 ++++++++-------- internal/downloader/client.go | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/crypto/blowfish.go b/internal/crypto/blowfish.go index 787dc1a..dc588d7 100644 --- a/internal/crypto/blowfish.go +++ b/internal/crypto/blowfish.go @@ -9,31 +9,31 @@ import ( ) var ( - iv = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07} - secretKey = []byte("g4el58wc0zvf9na1") + blowfishIV = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07} + blowfishSecretKey = []byte("g4el58wc0zvf9na1") ) -func GetKey(songID string) []byte { +func GetBlowfishKey(songID string) []byte { hash := md5.Sum([]byte(songID)) hashHex := hex.EncodeToString(hash[:]) - key := make([]byte, len(secretKey)) - copy(key, secretKey) - for i := 0; i < len(hash); i++ { + key := make([]byte, len(blowfishSecretKey)) + copy(key, blowfishSecretKey) + for i := range len(hash) { key[i] = key[i] ^ hashHex[i] ^ hashHex[i+16] } return key } -func Decrypt(data, key []byte) ([]byte, error) { +func DecryptBlowfish(data, key []byte) ([]byte, error) { block, err := blowfish.NewCipher(key) if err != nil { return nil, err } decrypted := make([]byte, len(data)) - cipher.NewCBCDecrypter(block, iv).CryptBlocks(decrypted, data) + cipher.NewCBCDecrypter(block, blowfishIV).CryptBlocks(decrypted, data) return decrypted, nil } diff --git a/internal/downloader/client.go b/internal/downloader/client.go index 4c7ba86..0c1d561 100644 --- a/internal/downloader/client.go +++ b/internal/downloader/client.go @@ -175,7 +175,7 @@ func (c *Client) downloadSong(ctx context.Context, resource deezer.Resource, son fileName := song.GetFileName(c.resourceType, mediaFormat) outputPath := path.Join(outputDir, fileName) - key := crypto.GetKey(song.ID) + key := crypto.GetBlowfishKey(song.ID) if err := c.streamToFile(dlCtx, stream, outputPath, key); err != nil { fileutil.DeleteFile(outputPath) return downloadResult{err: fmt.Errorf("failed to stream to file: %w", err)} @@ -233,7 +233,7 @@ func (c *Client) streamToFile(ctx context.Context, stream io.ReadCloser, outputP } if chunk%3 == 0 && totalRead == chunkSize { - buffer, err = crypto.Decrypt(buffer, key) + buffer, err = crypto.DecryptBlowfish(buffer, key) if err != nil { return err }