( XStorage xStorage,
String sStreamName,
byte[] pOldPass,
byte[] pNewPass )
| 221 | } |
| 222 | |
| 223 | public int ChangeStreamPass( XStorage xStorage, |
| 224 | String sStreamName, |
| 225 | byte[] pOldPass, |
| 226 | byte[] pNewPass ) |
| 227 | { |
| 228 | // open substream element |
| 229 | XStream xSubStream = null; |
| 230 | try |
| 231 | { |
| 232 | Object oSubStream = xStorage.openEncryptedStreamElement( sStreamName, ElementModes.WRITE, new String(pOldPass) ); |
| 233 | xSubStream = UnoRuntime.queryInterface( XStream.class, oSubStream ); |
| 234 | if ( xSubStream == null ) |
| 235 | { |
| 236 | Error( "Can't open substream '" + sStreamName + "'!" ); |
| 237 | return 0; |
| 238 | } |
| 239 | } |
| 240 | catch( Exception e ) |
| 241 | { |
| 242 | Error( "Can't open substream '" + sStreamName + "', exception : " + e + "!" ); |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | |
| 247 | // change the password for the stream |
| 248 | XEncryptionProtectedSource xStreamEncryption = |
| 249 | UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xSubStream ); |
| 250 | |
| 251 | if ( xStreamEncryption == null ) |
| 252 | { |
| 253 | Message( "Optional interface XEncryptionProtectedSource is not implemented, feature can not be tested!" ); |
| 254 | return -1; |
| 255 | } |
| 256 | |
| 257 | try { |
| 258 | xStreamEncryption.setEncryptionPassword( new String(pNewPass) ); |
| 259 | } |
| 260 | catch( Exception e ) |
| 261 | { |
| 262 | Error( "Can't change encryption key of the substream '" + sStreamName + "', exception:" + e ); |
| 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | // free the stream resources, garbage collector may remove the object too late |
| 267 | XComponent xComponent = UnoRuntime.queryInterface( XComponent.class, xSubStream ); |
| 268 | if ( xComponent == null ) |
| 269 | { |
| 270 | Error( "Can't get XComponent implementation from substream '" + sStreamName + "'!" ); |
| 271 | return 0; |
| 272 | } |
| 273 | xComponent.dispose(); |
| 274 | |
| 275 | return 1; |
| 276 | } |
| 277 | |
| 278 | public boolean setStorageTypeAndCheckProps( XStorage xStorage, String sMediaType, boolean bIsRoot, int nMode ) |
| 279 | { |
no test coverage detected