Skip to content

Commit

Permalink
formatted source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Suraiya Hameed committed Jan 24, 2017
1 parent 87f9960 commit e21face
Show file tree
Hide file tree
Showing 120 changed files with 48,198 additions and 53,982 deletions.
260 changes: 119 additions & 141 deletions src/main/java/com/microsoft/sqlserver/jdbc/AE.java
Original file line number Diff line number Diff line change
@@ -1,132 +1,116 @@
//---------------------------------------------------------------------------------------------------------------------------------
// File: AE.java
//
//
// Microsoft JDBC Driver for SQL Server
// Copyright(c) Microsoft Corporation
// All rights reserved.
// MIT License
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"),
// to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//---------------------------------------------------------------------------------------------------------------------------------

/*
* Microsoft JDBC Driver for SQL Server
*
* Copyright(c) Microsoft Corporation All rights reserved.
*
* This program is made available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/

package com.microsoft.sqlserver.jdbc;

import java.util.Vector;

/**
* Represents a single encrypted value for a CEK. It contains the encrypted CEK,the store type, name,the key path and encryption algorithm.
* Represents a single encrypted value for a CEK. It contains the encrypted CEK,the store type, name,the key path and encryption algorithm.
*/
class EncryptionKeyInfo {
EncryptionKeyInfo(
byte[] encryptedKeyVal,
int dbId,
int keyId,
int keyVersion,
byte[] mdVersion,
String keyPathVal,
String keyStoreNameVal,
String algorithmNameVal)
{
encryptedKey = encryptedKeyVal;
databaseId = dbId;
cekId = keyId;
cekVersion = keyVersion;
cekMdVersion = mdVersion;
keyPath = keyPathVal;
keyStoreName = keyStoreNameVal;
algorithmName = algorithmNameVal;
}
EncryptionKeyInfo(byte[] encryptedKeyVal,
int dbId,
int keyId,
int keyVersion,
byte[] mdVersion,
String keyPathVal,
String keyStoreNameVal,
String algorithmNameVal) {
encryptedKey = encryptedKeyVal;
databaseId = dbId;
cekId = keyId;
cekVersion = keyVersion;
cekMdVersion = mdVersion;
keyPath = keyPathVal;
keyStoreName = keyStoreNameVal;
algorithmName = algorithmNameVal;
}

byte[] encryptedKey; // the encrypted "column encryption key"
byte[] encryptedKey; // the encrypted "column encryption key"
int databaseId;
int cekId;
int cekVersion;
byte[] cekMdVersion;
String keyPath;
String keyStoreName;
String algorithmName;
byte normalizationRuleVersion;
byte normalizationRuleVersion;
}

/**
* Represents a unique CEK as an entry in the CekTable. A unique (plaintext is unique) CEK can have multiple
* encrypted CEKs when using multiple CMKs. These encrypted CEKs are represented by a member vector.
* Represents a unique CEK as an entry in the CekTable. A unique (plaintext is unique) CEK can have multiple encrypted CEKs when using multiple CMKs.
* These encrypted CEKs are represented by a member vector.
*/
class CekTableEntry
{
static final private java.util.logging.Logger aeLogger =
java.util.logging.Logger.getLogger("com.microsoft.sqlserver.jdbc.AE");

Vector<EncryptionKeyInfo> columnEncryptionKeyValues;
int ordinal;
int databaseId;
int cekId;
int cekVersion;
byte[] cekMdVersion;

Vector<EncryptionKeyInfo> getColumnEncryptionKeyValues() {
return columnEncryptionKeyValues;
}
class CekTableEntry {
static final private java.util.logging.Logger aeLogger = java.util.logging.Logger.getLogger("com.microsoft.sqlserver.jdbc.AE");

int getOrdinal() {
return ordinal;
}
Vector<EncryptionKeyInfo> columnEncryptionKeyValues;
int ordinal;
int databaseId;
int cekId;
int cekVersion;
byte[] cekMdVersion;

int getDatabaseId() {
return databaseId;
}
Vector<EncryptionKeyInfo> getColumnEncryptionKeyValues() {
return columnEncryptionKeyValues;
}

int getCekId() {
return cekId;
}

int getCekVersion() {
return cekVersion;
}
int getOrdinal() {
return ordinal;
}

byte[] getCekMdVersion() {
return cekMdVersion;
}

CekTableEntry(int ordinalVal)
{
int getDatabaseId() {
return databaseId;
}

int getCekId() {
return cekId;
}

int getCekVersion() {
return cekVersion;
}

byte[] getCekMdVersion() {
return cekMdVersion;
}

CekTableEntry(int ordinalVal) {
ordinal = ordinalVal;
databaseId = 0;
cekId = 0;
cekVersion = 0;
cekMdVersion = null;
columnEncryptionKeyValues = new Vector<EncryptionKeyInfo>();
}

int getSize(){
return columnEncryptionKeyValues.size();
}

void add(byte[] encryptedKey, int dbId, int keyId, int keyVersion, byte[] mdVersion, String keyPath, String keyStoreName, String algorithmName) {

int getSize() {
return columnEncryptionKeyValues.size();
}

void add(byte[] encryptedKey,
int dbId,
int keyId,
int keyVersion,
byte[] mdVersion,
String keyPath,
String keyStoreName,
String algorithmName) {

assert null != columnEncryptionKeyValues : "columnEncryptionKeyValues should already be initialized.";

if (aeLogger.isLoggable(java.util.logging.Level.FINE)){
aeLogger.fine("Retrieving CEK values");
}

EncryptionKeyInfo encryptionKey = new EncryptionKeyInfo(
encryptedKey,
dbId,
keyId,
keyVersion,
mdVersion,
keyPath,
keyStoreName,
algorithmName);
if (aeLogger.isLoggable(java.util.logging.Level.FINE)) {
aeLogger.fine("Retrieving CEK values");
}

EncryptionKeyInfo encryptionKey = new EncryptionKeyInfo(encryptedKey, dbId, keyId, keyVersion, mdVersion, keyPath, keyStoreName,
algorithmName);
columnEncryptionKeyValues.add(encryptionKey);

if (0 == databaseId) {
Expand All @@ -136,40 +120,36 @@ void add(byte[] encryptedKey, int dbId, int keyId, int keyVersion, byte[] mdVers
cekMdVersion = mdVersion;
}
else {
assert(databaseId == dbId);
assert(cekId == keyId);
assert(cekVersion == keyVersion);
assert (databaseId == dbId);
assert (cekId == keyId);
assert (cekVersion == keyVersion);
assert ((null != cekMdVersion) && (null != mdVersion) && (cekMdVersion.length == mdVersion.length));
}
}
}
}

/**
* Contains all CEKs, each row represents one unique CEK (represented by CekTableEntry).
*/
class CekTable
{
CekTableEntry[] keyList;

CekTable(int tableSize)
{
keyList = new CekTableEntry[tableSize];
}

int getSize()
{
return keyList.length;
}

CekTableEntry getCekTableEntry(int index)
{
return keyList[index];
}

void setCekTableEntry(int index, CekTableEntry entry)
{
keyList[index] = entry;
}
class CekTable {
CekTableEntry[] keyList;

CekTable(int tableSize) {
keyList = new CekTableEntry[tableSize];
}

int getSize() {
return keyList.length;
}

CekTableEntry getCekTableEntry(int index) {
return keyList[index];
}

void setCekTableEntry(int index,
CekTableEntry entry) {
keyList[index] = entry;
}
}

/**
Expand Down Expand Up @@ -275,17 +255,16 @@ enum DescribeParameterEncryptionResultSet1 {
KeyEncryptionAlgorithm;

private int value;

// Column indexing starts from 1;
static{
for (int i = 0; i < values().length; ++i)
{
values()[i].value = i + 1;
}
static {
for (int i = 0; i < values().length; ++i) {
values()[i].value = i + 1;
}
}
int value()
{
return value;

int value() {
return value;
}
}

Expand All @@ -301,17 +280,16 @@ enum DescribeParameterEncryptionResultSet2 {
NormalizationRuleVersion;

private int value;

// Column indexing starts from 1;
static{
for (int i = 0; i < values().length; ++i)
{
values()[i].value = i + 1;
}
static {
for (int i = 0; i < values().length; ++i) {
values()[i].value = i + 1;
}
}

int value() {
return value;
}
int value()
{
return value;
}

}
Loading

0 comments on commit e21face

Please sign in to comment.