Repository: snowflakedb/gosnowflake
Pull request #1401 (2025-05-06 08:33:31)

SNOW-2062018 Fix smkId downcast to int
### Description

SNOW-2062018 Fixed smkId that was cast to `int` type, which was system dependent.

### Checklist
- [x] Created tests which fail without the change (if possible)
- [ ] Extended the README / documentation, if necessary


sfc-gh-snowflakedb-snyk-sa: ![](https://res.cloudinary.com/snyk/image/upload/r-d/scm-platform/snyk-pull-requests/pr-banner-default.svg)

### :tada: **Snyk checks have passed. No issues have been found so far.**

:white_check_mark: **security/snyk** check is complete. No issues have been found. [(View Details)](https://app.snyk.io/org/snowflakedb-sca-scanning-public-repo/pr-checks/ff9017f5-f103-49ba-9f2f-5a699d5d16b5?refs=3f57cbb77948d77f1c0b7129e6de569a1e9ee5f3&source=prChecksComment)

:white_check_mark: **license/snyk** check is complete. No issues have been found. [(View Details)](https://app.snyk.io/org/snowflakedb-sca-scanning-public-repo/pr-checks/ff9017f5-f103-49ba-9f2f-5a699d5d16b5/license?refs=3f57cbb77948d77f1c0b7129e6de569a1e9ee5f3&source=prChecksComment)



codecov[bot]: ## [Codecov](https://app.codecov.io/gh/snowflakedb/gosnowflake/pull/1401?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 82.11%. Comparing base [(`d092186`)](https://app.codecov.io/gh/snowflakedb/gosnowflake/commit/d0921865822ada6dbbcc1a673a8810d436b9eb5e?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb) to head [(`841fd25`)](https://app.codecov.io/gh/snowflakedb/gosnowflake/commit/841fd250e05a9f7dc0cb320b4176bbd7ce005296?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #1401      +/-   ##
==========================================
- Coverage   82.11%   82.11%   -0.01%     
==========================================
  Files          58       58              
  Lines       14411    14411              
==========================================
- Hits        11834    11833       -1     
- Misses       2577     2578       +1     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/snowflakedb/gosnowflake/pull/1401?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).

<details><summary> :rocket: New features to boost your workflow: </summary>

- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>

Patch:
diff --git a/encrypt_util.go b/encrypt_util.go
index 0958aa9..b1187b2 100644
--- a/encrypt_util.go
+++ b/encrypt_util.go
@@ -95,7 +95,7 @@ func encryptStreamCBC(
 	}
 
 	matDesc := materialDescriptor{
-		strconv.Itoa(int(sfe.SMKID)),
+		fmt.Sprintf("%v", sfe.SMKID),
 		sfe.QueryID,
 		strconv.Itoa(keySize * 8),
 	}
@@ -378,7 +378,7 @@ func encryptFileGCM(
 	}
 
 	matDesc := materialDescriptor{
-		strconv.Itoa(int(sfe.SMKID)),
+		fmt.Sprintf("%v", sfe.SMKID),
 		sfe.QueryID,
 		strconv.Itoa(keySize * 8),
 	}


Test patch:
diff --git a/encrypt_util_test.go b/encrypt_util_test.go
index 0c980c1..e25d50c 100644
--- a/encrypt_util_test.go
+++ b/encrypt_util_test.go
@@ -27,7 +27,7 @@ func TestEncryptDecryptFileCBC(t *testing.T) {
 	encMat := snowflakeFileEncryption{
 		"ztke8tIdVt1zmlQIZm0BMA==",
 		"123873c7-3a66-40c4-ab89-e3722fbccce1",
-		3112,
+		9223372036854775807,
 	}
 	data := "test data"
 	inputFile := "test_encrypt_decrypt_file"
@@ -47,6 +47,7 @@ func TestEncryptDecryptFileCBC(t *testing.T) {
 		t.Error(err)
 	}
 	defer os.Remove(encryptedFile)
+	assertStringContainsE(t, metadata.matdesc, "9223372036854775807")
 	decryptedFile, err := decryptFileCBC(metadata, &encMat, encryptedFile, 0, "")
 	if err != nil {
 		t.Error(err)
@@ -273,10 +274,11 @@ func TestEncryptDecryptFileGCM(t *testing.T) {
 	sfe := &snowflakeFileEncryption{
 		QueryStageMasterKey: "YWJjZGVmMTIzNDU2Nzg5MA==",
 		QueryID:             "unused",
-		SMKID:               123,
+		SMKID:               9223372036854775807,
 	}
 	meta, encryptedFileName, err := encryptFileGCM(sfe, tempFile.Name(), tmpDir)
 	assertNilF(t, err)
+	assertStringContainsE(t, meta.matdesc, "9223372036854775807")
 
 	decryptedFileName, err := decryptFileGCM(meta, sfe, encryptedFileName, tmpDir)
 	assertNilF(t, err)